From 331353022a6d70b6da52c32d7bc584977479037a Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 1 May 2014 17:34:47 +0200 Subject: [PATCH] Rewrote all_t to use bool arguments instead of predicate and classes --- include/sqlpp11/basic_expression_operators.h | 4 +-- include/sqlpp11/detail/logic.h | 4 +-- include/sqlpp11/detail/type_set.h | 38 ++++++++++---------- include/sqlpp11/multi_column.h | 4 +-- include/sqlpp11/on.h | 2 +- include/sqlpp11/vendor/concat.h | 2 +- include/sqlpp11/vendor/extra_tables.h | 2 +- include/sqlpp11/vendor/from.h | 4 +-- include/sqlpp11/vendor/group_by.h | 4 +-- include/sqlpp11/vendor/having.h | 4 +-- include/sqlpp11/vendor/insert_value_list.h | 24 ++++++------- include/sqlpp11/vendor/order_by.h | 4 +-- include/sqlpp11/vendor/select_column_list.h | 8 ++--- include/sqlpp11/vendor/select_flag_list.h | 4 +-- include/sqlpp11/vendor/update_list.h | 10 +++--- include/sqlpp11/vendor/using.h | 4 +-- include/sqlpp11/vendor/where.h | 4 +-- 17 files changed, 62 insertions(+), 64 deletions(-) diff --git a/include/sqlpp11/basic_expression_operators.h b/include/sqlpp11/basic_expression_operators.h index b3e74d86..9e97a044 100644 --- a/include/sqlpp11/basic_expression_operators.h +++ b/include/sqlpp11/basic_expression_operators.h @@ -134,14 +134,14 @@ namespace sqlpp template vendor::in_t...> in(T... t) const { - static_assert(detail::all_t<_is_valid_comparison_operand, vendor::wrap_operand_t...>::value, "at least one operand of in() is not valid"); + static_assert(detail::all_t<_is_valid_comparison_operand>::value...>::value, "at least one operand of in() is not valid"); return { *static_cast(this), vendor::wrap_operand_t{t}... }; } template vendor::in_t...> not_in(T... t) const { - static_assert(detail::all_t<_is_valid_comparison_operand, vendor::wrap_operand_t...>::value, "at least one operand of in() is not valid"); + static_assert(detail::all_t<_is_valid_comparison_operand>::value...>::value, "at least one operand of in() is not valid"); return { *static_cast(this), vendor::wrap_operand_t{t}... }; } diff --git a/include/sqlpp11/detail/logic.h b/include/sqlpp11/detail/logic.h index 14527010..4f1dfb29 100644 --- a/include/sqlpp11/detail/logic.h +++ b/include/sqlpp11/detail/logic.h @@ -36,10 +36,10 @@ namespace sqlpp template struct logic_helper; - template class Predicate, typename... T> + template using all_t = std::integral_constant< bool, - std::is_same::value...>, logic_helper<(true or Predicate::value)...>>::value>; + std::is_same, logic_helper<(true or B)...>>::value>; template using any_t = std::integral_constant< diff --git a/include/sqlpp11/detail/type_set.h b/include/sqlpp11/detail/type_set.h index 63cef7d6..6aadd0b7 100644 --- a/include/sqlpp11/detail/type_set.h +++ b/include/sqlpp11/detail/type_set.h @@ -82,26 +82,6 @@ namespace sqlpp static constexpr bool value = any_t::value...>::value; }; - template - struct is_superset_of - { - static_assert(::sqlpp::vendor::wrong_t::value, "L and R have to be type sets"); - }; - - template - struct is_superset_of, type_set> - { - template - using is_element_of_L = is_element_of>; - static constexpr bool value = all_t::value; - }; - - template - struct is_subset_of - { - static constexpr bool value = is_superset_of::value; - }; - template struct joined_set { @@ -117,6 +97,24 @@ namespace sqlpp template using joined_set_t = typename joined_set::type; + template + struct is_superset_of + { + static_assert(::sqlpp::vendor::wrong_t::value, "L and R have to be type sets"); + }; + + template + struct is_superset_of, type_set> + { + static constexpr bool value = joined_set_t, type_set>::size::value == sizeof...(LElements); + }; + + template + struct is_subset_of + { + static constexpr bool value = is_superset_of::value; + }; + template struct is_disjunct_from { diff --git a/include/sqlpp11/multi_column.h b/include/sqlpp11/multi_column.h index 821cd1c2..89fdc464 100644 --- a/include/sqlpp11/multi_column.h +++ b/include/sqlpp11/multi_column.h @@ -41,7 +41,7 @@ namespace sqlpp template struct multi_column_t { - static_assert(detail::all_t::value, "multi_column parameters need to be named expressions"); + static_assert(detail::all_t::value...>::value, "multi_column parameters need to be named expressions"); using _table_set = sqlpp::detail::make_joined_set_t; @@ -75,7 +75,7 @@ namespace sqlpp template struct multi_column_alias_t { - static_assert(detail::all_t::value, "multi_column parameters need to be named expressions"); + static_assert(detail::all_t::value...>::value, "multi_column parameters need to be named expressions"); using _name_t = typename AliasProvider::_name_t; using _table_set = sqlpp::detail::make_joined_set_t; diff --git a/include/sqlpp11/on.h b/include/sqlpp11/on.h index da874957..25fc7e94 100644 --- a/include/sqlpp11/on.h +++ b/include/sqlpp11/on.h @@ -41,7 +41,7 @@ namespace sqlpp using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; static_assert(_is_dynamic::value or sizeof...(Expr), "at least one expression argument required in on()"); - static_assert(detail::all_t::value, "at least one argument is not an expression in on()"); + static_assert(detail::all_t::value...>::value, "at least one argument is not an expression in on()"); template void add(E expr) diff --git a/include/sqlpp11/vendor/concat.h b/include/sqlpp11/vendor/concat.h index c88aae93..332c17fc 100644 --- a/include/sqlpp11/vendor/concat.h +++ b/include/sqlpp11/vendor/concat.h @@ -39,7 +39,7 @@ namespace sqlpp struct concat_t: public First::_value_type::template expression_operators> { static_assert(sizeof...(Args) > 0, "concat requires two arguments at least"); - static_assert(sqlpp::detail::all_t::value, "at least one non-text argument detected in concat()"); + static_assert(sqlpp::detail::all_t::value, is_text_t::value...>::value, "at least one non-text argument detected in concat()"); using _table_set = typename ::sqlpp::detail::make_joined_set::type; struct _value_type: public First::_value_type::_base_value_type diff --git a/include/sqlpp11/vendor/extra_tables.h b/include/sqlpp11/vendor/extra_tables.h index 0b91ad7a..c9fceb77 100644 --- a/include/sqlpp11/vendor/extra_tables.h +++ b/include/sqlpp11/vendor/extra_tables.h @@ -45,7 +45,7 @@ namespace sqlpp static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in extra_tables()"); - static_assert(::sqlpp::detail::all_t::value, "at least one argument is not a table or join in extra_tables()"); + static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a table or join in extra_tables()"); using _table_set = ::sqlpp::detail::make_joined_set_t; diff --git a/include/sqlpp11/vendor/from.h b/include/sqlpp11/vendor/from.h index 6949cfee..ca9c1d8f 100644 --- a/include/sqlpp11/vendor/from.h +++ b/include/sqlpp11/vendor/from.h @@ -49,7 +49,7 @@ namespace sqlpp // FIXME: Joins contain two tables. This is not being dealt with at the moment when looking at duplicates, for instance static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in from()"); - static_assert(::sqlpp::detail::all_t::value, "at least one argument is not a table or join in from()"); + static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a table or join in from()"); using _table_set = ::sqlpp::detail::make_joined_set_t; @@ -73,7 +73,7 @@ namespace sqlpp static_assert(_is_dynamic::value, "add_from must not be called for static from()"); static_assert(is_table_t::value, "invalid table argument in add_from()"); - using ok = ::sqlpp::detail::all_t>; + using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_table_t
::value>; _add_from_impl(table, ok()); // dispatch to prevent compile messages after the static_assert } diff --git a/include/sqlpp11/vendor/group_by.h b/include/sqlpp11/vendor/group_by.h index 6d3dfba1..3bbc7049 100644 --- a/include/sqlpp11/vendor/group_by.h +++ b/include/sqlpp11/vendor/group_by.h @@ -54,7 +54,7 @@ namespace sqlpp static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in group_by()"); - static_assert(::sqlpp::detail::all_t::value, "at least one argument is not an expression in group_by()"); + static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an expression in group_by()"); group_by_t(Expressions... expressions): _expressions(expressions...) @@ -82,7 +82,7 @@ namespace sqlpp static_assert(is_expression_t::value, "invalid expression argument in add_group_by()"); static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in add_group_by()"); - using ok = ::sqlpp::detail::all_t>; + using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t::value>; _add_group_by_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert } diff --git a/include/sqlpp11/vendor/having.h b/include/sqlpp11/vendor/having.h index 20beeb97..51447187 100644 --- a/include/sqlpp11/vendor/having.h +++ b/include/sqlpp11/vendor/having.h @@ -47,7 +47,7 @@ namespace sqlpp using _parameter_tuple_t = std::tuple; static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression argument required in having()"); - static_assert(::sqlpp::detail::all_t::value, "at least one argument is not an expression in having()"); + static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an expression in having()"); using _parameter_list_t = typename make_parameter_list_t<_parameter_tuple_t>::type; @@ -79,7 +79,7 @@ namespace sqlpp static_assert(is_expression_t::value, "invalid expression argument in add_having()"); static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in add_having()"); - using ok = ::sqlpp::detail::all_t>; + using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t::value>; _add_having_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert } diff --git a/include/sqlpp11/vendor/insert_value_list.h b/include/sqlpp11/vendor/insert_value_list.h index 5bc38c66..8b70f9db 100644 --- a/include/sqlpp11/vendor/insert_value_list.h +++ b/include/sqlpp11/vendor/insert_value_list.h @@ -65,7 +65,7 @@ namespace sqlpp static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in set()"); - static_assert(sqlpp::detail::all_t::value, "at least one argument is not an assignment in set()"); + static_assert(sqlpp::detail::all_t::value...>::value, "at least one argument is not an assignment in set()"); static_assert(sqlpp::detail::none_t::value...>::value, "at least one assignment is prohibited by its column definition in set()"); @@ -101,12 +101,12 @@ namespace sqlpp static_assert(::sqlpp::detail::is_subset_of<_value_table_set, typename Policies::_table_set>::value, "add_set() contains a column from a foreign table"); static_assert(::sqlpp::detail::is_subset_of<_column_table_set, typename Policies::_table_set>::value, "add_set() contains a value from a foreign table"); - using ok = ::sqlpp::detail::all_t, - ::sqlpp::detail::not_t, - ::sqlpp::detail::is_subset_of<_value_table_set, typename Policies::_table_set>, - ::sqlpp::detail::is_subset_of<_column_table_set, typename Policies::_table_set>>; + using ok = ::sqlpp::detail::all_t< + _is_dynamic::value, + is_assignment_t::value, + not must_not_insert_t::value, + ::sqlpp::detail::is_subset_of<_value_table_set, typename Policies::_table_set>::value, + ::sqlpp::detail::is_subset_of<_column_table_set, typename Policies::_table_set>::value>; _add_set_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert } @@ -142,7 +142,7 @@ namespace sqlpp static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in columns()"); - static_assert(::sqlpp::detail::all_t::value, "at least one argument is not a column in columns()"); + static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a column in columns()"); static_assert(::sqlpp::detail::none_t::value...>::value, "at least one column argument has a must_not_insert flag in its definition"); @@ -167,14 +167,14 @@ namespace sqlpp template void add_values(Assignments... assignments) { - static_assert(::sqlpp::detail::all_t::value, "add_values() arguments have to be assignments"); + static_assert(::sqlpp::detail::all_t::value...>::value, "add_values() arguments have to be assignments"); using _arg_value_tuple = std::tuple...>; using _args_correct = std::is_same<_arg_value_tuple, _value_tuple_t>; static_assert(_args_correct::value, "add_values() arguments do not match columns() arguments"); - using ok = ::sqlpp::detail::all_t, - _args_correct>; + using ok = ::sqlpp::detail::all_t< + ::sqlpp::detail::all_t::value...>::value, + _args_correct::value>; _add_values_impl(ok(), assignments...); // dispatch to prevent compile messages after the static_assert } diff --git a/include/sqlpp11/vendor/order_by.h b/include/sqlpp11/vendor/order_by.h index 9eae6c43..724239b0 100644 --- a/include/sqlpp11/vendor/order_by.h +++ b/include/sqlpp11/vendor/order_by.h @@ -53,7 +53,7 @@ namespace sqlpp static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in order_by()"); - static_assert(::sqlpp::detail::all_t::value, "at least one argument is not a sort order expression in order_by()"); + static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a sort order expression in order_by()"); order_by_t(Expressions... expressions): _expressions(expressions...) @@ -81,7 +81,7 @@ namespace sqlpp static_assert(is_sort_order_t::value, "invalid expression argument in add_order_by()"); static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in add_order_by()"); - using ok = ::sqlpp::detail::all_t>; + using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_sort_order_t::value>; _add_order_by_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert } diff --git a/include/sqlpp11/vendor/select_column_list.h b/include/sqlpp11/vendor/select_column_list.h index 52a48045..5c06710f 100644 --- a/include/sqlpp11/vendor/select_column_list.h +++ b/include/sqlpp11/vendor/select_column_list.h @@ -143,7 +143,7 @@ namespace sqlpp template using is_valid_expression_t = std::integral_constant::value or is_multi_column_t::value>; - static_assert(::sqlpp::detail::all_t::value, "at least one argument is not a named expression"); + static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a named expression"); static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate name detected"); @@ -206,9 +206,9 @@ namespace sqlpp using column_names = ::sqlpp::detail::make_type_set_t; static_assert(not ::sqlpp::detail::is_element_of::value, "a column of this name is present in the select already"); - using ok = ::sqlpp::detail::all_t + using ok = ::sqlpp::detail::all_t< + _is_dynamic::value, + is_named_expression_t::value >; _add_column_impl(namedExpression, ok()); // dispatch to prevent compile messages after the static_assert diff --git a/include/sqlpp11/vendor/select_flag_list.h b/include/sqlpp11/vendor/select_flag_list.h index 93384318..a5e9036b 100644 --- a/include/sqlpp11/vendor/select_flag_list.h +++ b/include/sqlpp11/vendor/select_flag_list.h @@ -50,7 +50,7 @@ namespace sqlpp static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in select flag list"); - static_assert(::sqlpp::detail::all_t::value, "at least one argument is not a select flag in select flag list"); + static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a select flag in select flag list"); select_flag_list_t(Flags... flags): _flags(flags...) @@ -78,7 +78,7 @@ namespace sqlpp static_assert(is_select_flag_t::value, "invalid select flag argument in add_flag()"); static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "flag uses tables unknown to this statement in add_flag()"); - using ok = ::sqlpp::detail::all_t>; + using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_select_flag_t::value>; _add_flag_impl(flag, ok()); // dispatch to prevent compile messages after the static_assert } diff --git a/include/sqlpp11/vendor/update_list.h b/include/sqlpp11/vendor/update_list.h index c3539629..9b0c808c 100644 --- a/include/sqlpp11/vendor/update_list.h +++ b/include/sqlpp11/vendor/update_list.h @@ -48,7 +48,7 @@ namespace sqlpp static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in set()"); - static_assert(::sqlpp::detail::all_t::value, "at least one argument is not an assignment in set()"); + static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an assignment in set()"); static_assert(::sqlpp::detail::none_t::value...>::value, "at least one assignment is prohibited by its column definition in set()"); @@ -85,10 +85,10 @@ namespace sqlpp static_assert(sqlpp::detail::not_t::value, "add_set() argument must not be updated"); static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "assignment uses tables unknown to this statement in add_set()"); - using ok = ::sqlpp::detail::all_t, - sqlpp::detail::not_t>; + using ok = ::sqlpp::detail::all_t< + _is_dynamic::value, + is_assignment_t::value, + not must_not_update_t::value>; _add_set_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert } diff --git a/include/sqlpp11/vendor/using.h b/include/sqlpp11/vendor/using.h index eaaea22f..64415e9d 100644 --- a/include/sqlpp11/vendor/using.h +++ b/include/sqlpp11/vendor/using.h @@ -49,7 +49,7 @@ namespace sqlpp static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in using()"); - static_assert(::sqlpp::detail::all_t::value, "at least one argument is not an table in using()"); + static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an table in using()"); using _table_set = ::sqlpp::detail::make_joined_set_t; @@ -72,7 +72,7 @@ namespace sqlpp static_assert(_is_dynamic::value, "add_using must not be called for static using()"); static_assert(is_table_t
::value, "invalid table argument in add_using()"); - using ok = ::sqlpp::detail::all_t>; + using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_table_t
::value>; _add_using_impl(table, ok()); // dispatch to prevent compile messages after the static_assert } diff --git a/include/sqlpp11/vendor/where.h b/include/sqlpp11/vendor/where.h index dad97616..63882e0a 100644 --- a/include/sqlpp11/vendor/where.h +++ b/include/sqlpp11/vendor/where.h @@ -48,7 +48,7 @@ namespace sqlpp static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression argument required in where()"); static_assert(sqlpp::detail::none_t::value...>::value, "at least one argument is an assignment in where()"); - static_assert(sqlpp::detail::all_t::value, "at least one argument is not valid expression in where()"); + static_assert(sqlpp::detail::all_t::value...>::value, "at least one argument is not valid expression in where()"); using _parameter_list_t = typename make_parameter_list_t<_parameter_tuple_t>::type; @@ -80,7 +80,7 @@ namespace sqlpp static_assert(is_expression_t::value, "invalid expression argument in add_where()"); static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in add_where()"); - using ok = ::sqlpp::detail::all_t>; + using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t::value>; _add_where_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert }