From 61030742b3dc23118794c8d7d4bc241b6d4b8234 Mon Sep 17 00:00:00 2001 From: Roland Bock Date: Sun, 14 Jul 2024 12:09:00 +0200 Subject: [PATCH] Removing more instances of wrap_operand --- docs/DifferencesToVersion-1.0.md | 2 + include/sqlpp11/aggregate_functions/avg.h | 59 ++---- include/sqlpp11/aggregate_functions/sum.h | 59 ++---- include/sqlpp11/any.h | 21 +- include/sqlpp11/case.h | 14 +- include/sqlpp11/column.h | 15 +- include/sqlpp11/cte.h | 1 - .../sqlpp11/data_types/parameter_value_base.h | 4 +- include/sqlpp11/expression.h | 200 ------------------ include/sqlpp11/functions.h | 72 ------- include/sqlpp11/group_by.h | 1 - include/sqlpp11/having.h | 1 - include/sqlpp11/in.h | 118 ----------- include/sqlpp11/insert_value.h | 11 +- include/sqlpp11/into.h | 2 +- include/sqlpp11/is_not_null.h | 79 ------- include/sqlpp11/is_null.h | 79 ------- include/sqlpp11/limit.h | 10 +- include/sqlpp11/lower.h | 47 ++-- include/sqlpp11/not_in.h | 118 ----------- include/sqlpp11/offset.h | 10 +- include/sqlpp11/operator/assign_expression.h | 1 + include/sqlpp11/operator/in_expression.h | 48 +++++ include/sqlpp11/select.h | 1 - include/sqlpp11/some.h | 21 +- include/sqlpp11/trim.h | 47 ++-- include/sqlpp11/union.h | 1 - include/sqlpp11/upper.h | 47 ++-- include/sqlpp11/value.h | 1 - include/sqlpp11/value_or_null.h | 85 -------- include/sqlpp11/where.h | 1 - include/sqlpp11/with.h | 1 - tests/core/types/aggregate_functions.cpp | 33 ++- tests/core/types/comparison_expression.cpp | 2 - 34 files changed, 208 insertions(+), 1004 deletions(-) delete mode 100644 include/sqlpp11/expression.h delete mode 100644 include/sqlpp11/in.h delete mode 100644 include/sqlpp11/is_not_null.h delete mode 100644 include/sqlpp11/is_null.h delete mode 100644 include/sqlpp11/not_in.h delete mode 100644 include/sqlpp11/value_or_null.h 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