From 8ae9966f5dda402a4e8a0afaf28ff8f4d2804a6e Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 8 Nov 2015 20:07:22 +0100 Subject: [PATCH] Started to migrate integral operators. Looks good... --- include/sqlpp11/basic_expression_operators.h | 42 +++++++++ .../data_types/boolean/expression_operators.h | 1 - .../integral/expression_operators.h | 94 +++++++++---------- include/sqlpp11/expression_return_types.h | 60 ++++++++++++ 4 files changed, 148 insertions(+), 49 deletions(-) diff --git a/include/sqlpp11/basic_expression_operators.h b/include/sqlpp11/basic_expression_operators.h index 5f8e211e..36557303 100644 --- a/include/sqlpp11/basic_expression_operators.h +++ b/include/sqlpp11/basic_expression_operators.h @@ -239,6 +239,48 @@ namespace sqlpp return_type_or::check::_(); return {*static_cast(this), wrap_operand_t{r}}; } + + template + auto operator+(const R& r) const -> return_type_plus_t + { + return_type_plus::check::_(); + return {*static_cast(this), wrap_operand_t{r}}; + } + + template + auto operator-(const R& r) const -> return_type_minus_t + { + return_type_minus::check::_(); + return {*static_cast(this), wrap_operand_t{r}}; + } + + template + auto operator*(const R& r) const -> return_type_multiplies_t + { + return_type_multiplies::check::_(); + return {*static_cast(this), wrap_operand_t{r}}; + } + + template + auto operator/(const R& r) const -> return_type_divides_t + { + return_type_divides::check::_(); + return {*static_cast(this), wrap_operand_t{r}}; + } + + template + auto operator+() const -> return_type_unary_plus_t + { + return_type_unary_plus::check::_(); + return {*static_cast(this)}; + } + + template + auto operator-() const -> return_type_unary_minus_t + { + return_type_unary_minus::check::_(); + return {*static_cast(this)}; + } }; } diff --git a/include/sqlpp11/data_types/boolean/expression_operators.h b/include/sqlpp11/data_types/boolean/expression_operators.h index 1e890b3e..41b946bd 100644 --- a/include/sqlpp11/data_types/boolean/expression_operators.h +++ b/include/sqlpp11/data_types/boolean/expression_operators.h @@ -27,7 +27,6 @@ #ifndef SQLPP_BOOLEAN_EXPRESSION_OPERATORS_H #define SQLPP_BOOLEAN_EXPRESSION_OPERATORS_H -//#include #include #include #include diff --git a/include/sqlpp11/data_types/integral/expression_operators.h b/include/sqlpp11/data_types/integral/expression_operators.h index 2cfe3be9..ff41a908 100644 --- a/include/sqlpp11/data_types/integral/expression_operators.h +++ b/include/sqlpp11/data_types/integral/expression_operators.h @@ -27,6 +27,8 @@ #ifndef SQLPP_INTEGRAL_EXPRESSION_OPERATORS_H #define SQLPP_INTEGRAL_EXPRESSION_OPERATORS_H +#include +#include #include #include #include @@ -35,84 +37,80 @@ namespace sqlpp { - template - struct expression_operators : public basic_expression_operators + template + struct expression_operators : public basic_expression_operators { template using _is_valid_operand = is_valid_operand; template - plus_t, wrap_operand_t> operator+(T t) const + modulus_t> operator%(T t) const { using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs operand"); - return {*static_cast(this), {t}}; + return {*static_cast(this), {t}}; } template - minus_t, wrap_operand_t> operator-(T t) const + bitwise_and_t, wrap_operand_t> operator&(T t) const { using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs operand"); - return {*static_cast(this), {t}}; + return {*static_cast(this), {t}}; } template - multiplies_t, wrap_operand_t> operator*(T t) const + bitwise_or_t, wrap_operand_t> operator|(T t) const { using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs operand"); - return {*static_cast(this), {t}}; + return {*static_cast(this), {t}}; } + }; - template - divides_t> operator/(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); + template + struct return_type_plus> + { + using check = consistent_t; + using type = plus_t, value_type_of>, wrap_operand_t>; + }; - return {*static_cast(this), {t}}; - } + template + struct return_type_minus> + { + using check = consistent_t; + using type = minus_t, value_type_of>, wrap_operand_t>; + }; - template - modulus_t> operator%(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); + template + struct return_type_multiplies> + { + using check = consistent_t; + using type = multiplies_t, value_type_of>, wrap_operand_t>; + }; - return {*static_cast(this), {t}}; - } + template + struct return_type_divides> + { + using check = consistent_t; + using type = divides_t, wrap_operand_t>; + }; - unary_plus_t operator+() const - { - return {*static_cast(this)}; - } + template + struct return_type_unary_plus> + { + using check = consistent_t; + using type = unary_plus_t>; + }; - unary_minus_t operator-() const - { - return {*static_cast(this)}; - } - - template - bitwise_and_t, wrap_operand_t> operator&(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); - - return {*static_cast(this), {t}}; - } - - template - bitwise_or_t, wrap_operand_t> operator|(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); - - return {*static_cast(this), {t}}; - } + template + struct return_type_unary_minus> + { + using check = consistent_t; + using type = unary_minus_t>; }; } #endif diff --git a/include/sqlpp11/expression_return_types.h b/include/sqlpp11/expression_return_types.h index 43f31ae4..dc64eaea 100644 --- a/include/sqlpp11/expression_return_types.h +++ b/include/sqlpp11/expression_return_types.h @@ -60,6 +60,66 @@ namespace sqlpp template using return_type_not_t = typename return_type_not::type; + + template + struct return_type_plus + { + using check = assert_valid_operands; + using type = bad_expression; + }; + + template + using return_type_plus_t = typename return_type_plus::type; + + template + struct return_type_minus + { + using check = assert_valid_operands; + using type = bad_expression; + }; + + template + using return_type_minus_t = typename return_type_minus::type; + + template + struct return_type_multiplies + { + using check = assert_valid_operands; + using type = bad_expression; + }; + + template + using return_type_multiplies_t = typename return_type_multiplies::type; + + template + struct return_type_divides + { + using check = assert_valid_operands; + using type = bad_expression; + }; + + template + using return_type_divides_t = typename return_type_divides::type; + + template + struct return_type_unary_plus + { + using check = assert_valid_operands; + using type = bad_expression; + }; + + template + using return_type_unary_plus_t = typename return_type_unary_plus::type; + + template + struct return_type_unary_minus + { + using check = assert_valid_operands; + using type = bad_expression; + }; + + template + using return_type_unary_minus_t = typename return_type_unary_minus::type; } #endif