diff --git a/docs/DifferencesToVersion-1.0.md b/docs/DifferencesToVersion-1.0.md index 554a36bc..f43f2686 100644 --- a/docs/DifferencesToVersion-1.0.md +++ b/docs/DifferencesToVersion-1.0.md @@ -37,3 +37,5 @@ SQLPP_ALIAS_PROVIDER(max_price); std::cout << row.max_price << '\n'; } ``` + + diff --git a/include/sqlpp11/aggregate_functions/avg.h b/include/sqlpp11/aggregate_functions/avg.h index 158760ee..576d7b45 100644 --- a/include/sqlpp11/aggregate_functions/avg.h +++ b/include/sqlpp11/aggregate_functions/avg.h @@ -31,44 +31,13 @@ namespace sqlpp { - struct avg_alias_t - { - struct _alias_t - { - static constexpr const char _literal[] = "avg_"; - using _name_t = sqlpp::make_char_sequence; - template - struct _member_t - { - T avg; - T& operator()() - { - return avg; - } - const T& operator()() const - { - return avg; - } - }; - }; - }; - template - struct avg_t : public expression_operators, floating_point>, - public aggregate_function_operators>, - public alias_operators> + struct avg_t { - using _traits = make_traits; using _nodes = detail::type_vector; using _can_be_null = std::true_type; using _is_aggregate_expression = std::true_type; - static_assert(is_noop::value or std::is_same::value, - "avg() used with flag other than 'distinct'"); - static_assert(is_numeric_t::value, "avg() requires a value expression as argument"); - - using _auto_alias_t = avg_alias_t; - avg_t(Expr expr) : _expr(expr) { } @@ -82,6 +51,12 @@ namespace sqlpp Expr _expr; }; + template + struct value_type_of> + { + using type = sqlpp::force_optional_t; + }; + template Context& serialize(const avg_t& t, Context& context) { @@ -97,20 +72,18 @@ namespace sqlpp } template - auto avg(T t) -> avg_t> + using check_avg_arg = + std::enable_if_t<(is_numeric::value or is_boolean::value) and not contains_aggregate_function_t::value>; + + template > + auto avg(T t) -> avg_t { - static_assert(not contains_aggregate_function_t>::value, - "avg() cannot be used on an aggregate function"); - static_assert(is_numeric_t>::value, "avg() requires a numeric value expression as argument"); - return {t}; + return {std::move(t)}; } - template - auto avg(const distinct_t& /*unused*/, T t) -> avg_t> + template > + auto avg(const distinct_t& /*unused*/, T t) -> avg_t { - static_assert(not contains_aggregate_function_t>::value, - "avg() cannot be used on an aggregate function"); - static_assert(is_numeric_t>::value, "avg() requires a numeric value expression as argument"); - return {t}; + return {std::move(t)}; } } // namespace sqlpp diff --git a/include/sqlpp11/aggregate_functions/sum.h b/include/sqlpp11/aggregate_functions/sum.h index c299f7f4..2b54b53e 100644 --- a/include/sqlpp11/aggregate_functions/sum.h +++ b/include/sqlpp11/aggregate_functions/sum.h @@ -31,44 +31,14 @@ namespace sqlpp { - struct sum_alias_t - { - struct _alias_t - { - static constexpr const char _literal[] = "sum_"; - using _name_t = sqlpp::make_char_sequence; - template - struct _member_t - { - T sum; - T& operator()() - { - return sum; - } - const T& operator()() const - { - return sum; - } - }; - }; - }; - template - struct sum_t : public expression_operators, value_type_of_t>, - public aggregate_function_operators>, - public alias_operators> + struct sum_t { using _traits = make_traits, tag::is_expression, tag::is_selectable>; using _nodes = detail::type_vector; using _can_be_null = std::true_type; using _is_aggregate_expression = std::true_type; - static_assert(is_noop::value or std::is_same::value, - "sum() used with flag other than 'distinct'"); - static_assert(is_numeric_t::value, "sum() requires a numeric expression as argument"); - - using _auto_alias_t = sum_alias_t; - sum_t(Expr expr) : _expr(expr) { } @@ -82,6 +52,13 @@ namespace sqlpp Expr _expr; }; + template + struct value_type_of> + { + using type = sqlpp::force_optional_t< + typename std::conditional::value, integral, value_type_of_t>::type>; + }; + template Context& serialize(const sum_t& t, Context& context) { @@ -97,20 +74,18 @@ namespace sqlpp } template - auto sum(T t) -> sum_t> + using check_sum_arg = + std::enable_if_t<(is_numeric::value or is_boolean::value) and not contains_aggregate_function_t::value>; + + template > + auto sum(T t) -> sum_t { - static_assert(not contains_aggregate_function_t>::value, - "sum() cannot be used on an aggregate function"); - static_assert(is_numeric_t>::value, "sum() requires a numeric expression as argument"); - return {t}; + return {std::move(t)}; } - template - auto sum(const distinct_t& /*unused*/, T t) -> sum_t> + template > + auto sum(const distinct_t& /*unused*/, T t) -> sum_t { - static_assert(not contains_aggregate_function_t>::value, - "sum() cannot be used on an aggregate function"); - static_assert(is_numeric_t>::value, "sum() requires a numeric expression as argument"); - return {t}; + return {std::move(t)}; } } // namespace sqlpp diff --git a/include/sqlpp11/any.h b/include/sqlpp11/any.h index 6aba53fb..147d9fc1 100644 --- a/include/sqlpp11/any.h +++ b/include/sqlpp11/any.h @@ -26,7 +26,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include #include #include @@ -51,6 +51,11 @@ namespace sqlpp Select _select; }; + template + struct value_type_of> : value_type_of& t, Context& context) { @@ -59,13 +64,13 @@ namespace sqlpp return context; } - template - auto any(T t) -> any_t> +#warning: Need tests + template + using check_any_args = std::enable_if_t::value and has_value_type + { + }; + template Context& serialize(const some_t