diff --git a/include/sqlpp11/detail/type_set.h b/include/sqlpp11/detail/type_set.h index a63e0caf..d367101f 100644 --- a/include/sqlpp11/detail/type_set.h +++ b/include/sqlpp11/detail/type_set.h @@ -29,49 +29,27 @@ #include #include +#include namespace sqlpp { namespace detail { + // some forward declarations and helpers template struct make_set; template class type_set_element {}; - template - struct is_superset_of_impl - : std::false_type {}; - - template - struct is_superset_of_impl - : std::true_type {}; - - template - struct is_superset_of_impl - : std::integral_constant::value and is_superset_of_impl::value> {}; - - template - struct is_disjunct_from_impl - : std::false_type {}; - - template - struct is_disjunct_from_impl - : std::true_type {}; - - template - struct is_disjunct_from_impl - : std::integral_constant::value and is_disjunct_from_impl::value> {}; - + // A type set template struct type_set: type_set_element... { - struct size: std::integral_constant {}; + using size = std::integral_constant; template - struct contains - : std::integral_constant, type_set>::value> {}; + using count = std::is_base_of, type_set>; template struct is_superset_of @@ -81,7 +59,7 @@ namespace sqlpp template struct is_superset_of> - : is_superset_of_impl{}; + : and_t {}; template struct join @@ -93,16 +71,6 @@ namespace sqlpp struct join> : make_set {}; - template - struct is_disjunct_from - { - static_assert(::sqlpp::vendor::wrong_t::value, "invalid argument for is_disjunct_from"); - }; - - template - struct is_disjunct_from> - : is_disjunct_from_impl{}; - template struct is_subset_of { @@ -111,20 +79,19 @@ namespace sqlpp template struct is_subset_of> - : is_superset_of_impl, Element...>{}; + : type_set::template is_superset_of{}; template - struct equals + struct is_disjunct_from { - static_assert(::sqlpp::vendor::wrong_t::value, "invalid argument for equals"); + static_assert(::sqlpp::vendor::wrong_t::value, "invalid argument for is_disjunct_from"); }; template - struct equals> - : std::integral_constant, Element...>::value - and - is_superset_of_impl, T...>::value> {}; + struct is_disjunct_from> + { + static constexpr bool value = not(or_t::value or or_t::template count, Element...>::value); + }; template struct insert @@ -133,23 +100,18 @@ namespace sqlpp }; template - struct insert::value>::type> + struct insert::value>::type> { using type = type_set; }; - template class Predicate, typename T, typename Enable = void> - struct insert_if - { - using type = type_set; - }; - template class Predicate, typename T> - struct insert_if::value and Predicate::value>::type> + struct insert_if { - using type = type_set; + using type = typename std::conditional::value, + type_set, + type_set>::type; }; - }; template<> @@ -182,17 +144,13 @@ namespace sqlpp template class Predicate, typename... T> struct make_set_if_not { - template - struct InversePredicate - { - static constexpr bool value = not Predicate::value; - }; + template + using InversePredicate = std::integral_constant::value>; using type = typename make_set_if::type; }; template - struct has_duplicates - : std::integral_constant::type::size::value != sizeof...(T)> {}; + using has_duplicates = std::integral_constant::type::size::value != sizeof...(T)>; } } diff --git a/include/sqlpp11/multi_column.h b/include/sqlpp11/multi_column.h index 4d9cbc38..8cf50469 100644 --- a/include/sqlpp11/multi_column.h +++ b/include/sqlpp11/multi_column.h @@ -27,8 +27,9 @@ #ifndef SQLPP_MULTI_COLUMN_H #define SQLPP_MULTI_COLUMN_H -#include #include +#include +#include namespace sqlpp { @@ -41,8 +42,7 @@ namespace sqlpp template struct multi_column_t> { - using _named_expr_set = typename detail::make_set_if::type; - static_assert(_named_expr_set::size::value == sizeof...(NamedExpr), "multi_column parameters need to be named expressions"); + static_assert(detail::and_t::value, "multi_column parameters need to be named expressions"); using _name_t = typename AliasProvider::_name_t; diff --git a/include/sqlpp11/on.h b/include/sqlpp11/on.h index c8ab0b0b..68c1297d 100644 --- a/include/sqlpp11/on.h +++ b/include/sqlpp11/on.h @@ -28,9 +28,9 @@ #define SQLPP_ON_H #include -#include #include #include +#include namespace sqlpp { @@ -41,8 +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()"); - using _valid_expressions = typename detail::make_set_if::type; - static_assert(_valid_expressions::size::value == sizeof...(Expr), "at least one argument is not an expression in on()"); + static_assert(detail::and_t::value, "at least one argument is not an expression in on()"); template void add(E expr) diff --git a/include/sqlpp11/vendor/column_list.h b/include/sqlpp11/vendor/column_list.h index 289cf25f..e8bbdb9a 100644 --- a/include/sqlpp11/vendor/column_list.h +++ b/include/sqlpp11/vendor/column_list.h @@ -28,7 +28,7 @@ #define SQLPP_COLUMN_LIST_H #include -#include +#include #include #include @@ -49,12 +49,10 @@ namespace sqlpp static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in columns()"); // check for invalid columns - using _column_set = typename ::sqlpp::detail::make_set_if::type; - static_assert(_column_set::size::value == sizeof...(Columns), "at least one argument is not a column in columns()"); + static_assert(::sqlpp::detail::and_t::value, "at least one argument is not a column in columns()"); // check for prohibited columns - using _prohibited_column_set = typename ::sqlpp::detail::make_set_if::type; - static_assert(_prohibited_column_set::size::value == 0, "at least one column argument has a must_not_insert flag in its definition"); + static_assert(not ::sqlpp::detail::or_t::value, "at least one column argument has a must_not_insert flag in its definition"); std::tuple...> _columns; }; diff --git a/include/sqlpp11/vendor/concat.h b/include/sqlpp11/vendor/concat.h index 0f2acc8d..232e92d2 100644 --- a/include/sqlpp11/vendor/concat.h +++ b/include/sqlpp11/vendor/concat.h @@ -29,7 +29,7 @@ #include #include -#include +#include namespace sqlpp { @@ -39,8 +39,7 @@ namespace sqlpp struct concat_t: public First::_value_type::template operators> { static_assert(sizeof...(Args) > 0, "concat requires two arguments at least"); - using _valid_args = typename ::sqlpp::detail::make_set_if_not::type; - static_assert(_valid_args::size::value == 0, "at least one non-text argument detected in concat()"); + static_assert(sqlpp::detail::and_t::value, "at least one non-text argument detected in concat()"); struct _value_type: public First::_value_type::_base_value_type { diff --git a/include/sqlpp11/vendor/from.h b/include/sqlpp11/vendor/from.h index da152d0d..11e8c999 100644 --- a/include/sqlpp11/vendor/from.h +++ b/include/sqlpp11/vendor/from.h @@ -27,11 +27,11 @@ #ifndef SQLPP_FROM_H #define SQLPP_FROM_H -#include #include #include #include #include +#include namespace sqlpp { @@ -50,8 +50,7 @@ namespace sqlpp static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in from()"); // check for invalid arguments - using _valid_expressions = typename ::sqlpp::detail::make_set_if::type; - static_assert(_valid_expressions::size::value == sizeof...(TableOrJoin), "at least one argument is not a table or join in from()"); + static_assert(::sqlpp::detail::and_t::value, "at least one argument is not a table or join in from()"); // FIXME: Joins contain two tables. This is not being dealt with at the moment when looking at duplicates, for instance diff --git a/include/sqlpp11/vendor/group_by.h b/include/sqlpp11/vendor/group_by.h index 1e5480cf..ca8e2e5e 100644 --- a/include/sqlpp11/vendor/group_by.h +++ b/include/sqlpp11/vendor/group_by.h @@ -32,7 +32,7 @@ #include #include #include -#include +#include namespace sqlpp { @@ -52,8 +52,7 @@ namespace sqlpp static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in group_by()"); // check for invalid expressions - using _valid_expressions = typename ::sqlpp::detail::make_set_if::type; - static_assert(_valid_expressions::size::value == sizeof...(Expr), "at least one argument is not an expression in group_by()"); + static_assert(::sqlpp::detail::and_t::value, "at least one argument is not an expression in group_by()"); template void add(E expr) diff --git a/include/sqlpp11/vendor/having.h b/include/sqlpp11/vendor/having.h index dd6be6d4..e9a474df 100644 --- a/include/sqlpp11/vendor/having.h +++ b/include/sqlpp11/vendor/having.h @@ -31,7 +31,7 @@ #include #include #include -#include +#include namespace sqlpp { @@ -45,8 +45,7 @@ namespace sqlpp using _parameter_tuple_t = std::tuple; static_assert(_is_dynamic::value or sizeof...(Expr), "at least one expression argument required in having()"); - using _valid_expressions = typename ::sqlpp::detail::make_set_if::type; - static_assert(_valid_expressions::size::value == sizeof...(Expr), "at least one argument is not an expression in having()"); + static_assert(::sqlpp::detail::and_t::value, "at least one argument is not an expression in having()"); using _parameter_list_t = typename make_parameter_list_t<_parameter_tuple_t>::type; diff --git a/include/sqlpp11/vendor/insert_list.h b/include/sqlpp11/vendor/insert_list.h index ac1680b0..f76a62b2 100644 --- a/include/sqlpp11/vendor/insert_list.h +++ b/include/sqlpp11/vendor/insert_list.h @@ -28,10 +28,10 @@ #define SQLPP_INSERT_LIST_H #include -#include #include #include #include +#include namespace sqlpp { @@ -69,12 +69,10 @@ namespace sqlpp static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in set()"); // check for invalid assignments - using _assignment_set = typename ::sqlpp::detail::make_set_if::type; - static_assert(_assignment_set::size::value == sizeof...(Assignments), "at least one argument is not an assignment in set()"); + static_assert(sqlpp::detail::and_t::value, "at least one argument is not an assignment in set()"); // check for prohibited assignments - using _prohibited_assignment_set = typename ::sqlpp::detail::make_set_if::type; - static_assert(_prohibited_assignment_set::size::value == 0, "at least one assignment is prohibited by its column definition in set()"); + static_assert(not sqlpp::detail::or_t::value, "at least one assignment is prohibited by its column definition in set()"); insert_list_t(Assignments... assignment): _columns({assignment._lhs}...), diff --git a/include/sqlpp11/vendor/insert_value_list.h b/include/sqlpp11/vendor/insert_value_list.h index a42cff0f..76fc1552 100644 --- a/include/sqlpp11/vendor/insert_value_list.h +++ b/include/sqlpp11/vendor/insert_value_list.h @@ -28,7 +28,7 @@ #define SQLPP_INSERT_VALUE_LIST_H #include -#include +#include #include #include @@ -44,8 +44,7 @@ namespace sqlpp static_assert(sizeof...(InsertValues), "at least one insert value required"); // check for invalid arguments - using _insert_values_set = typename ::sqlpp::detail::make_set_if::type; - static_assert(_insert_values_set::size::value == sizeof...(InsertValues), "at least one argument is not an insert value"); + static_assert(::sqlpp::detail::and_t::value, "at least one argument is not an insert value"); using _value_tuple_t = std::tuple; diff --git a/include/sqlpp11/vendor/order_by.h b/include/sqlpp11/vendor/order_by.h index 34ee6c1d..fd58485f 100644 --- a/include/sqlpp11/vendor/order_by.h +++ b/include/sqlpp11/vendor/order_by.h @@ -51,8 +51,7 @@ namespace sqlpp static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in order_by()"); // check for invalid order expressions - using _valid_expressions = typename ::sqlpp::detail::make_set_if::type; - static_assert(_valid_expressions::size::value == sizeof...(Expr), "at least one argument is not a sort order expression in order_by()"); + static_assert(::sqlpp::detail::and_t::value, "at least one argument is not a sort order expression in order_by()"); template void add(E expr) diff --git a/include/sqlpp11/vendor/select_column_list.h b/include/sqlpp11/vendor/select_column_list.h index dcbcc8e6..ce421e8f 100644 --- a/include/sqlpp11/vendor/select_column_list.h +++ b/include/sqlpp11/vendor/select_column_list.h @@ -31,9 +31,9 @@ #include #include #include -#include #include #include +#include #include #include #include @@ -149,9 +149,8 @@ namespace sqlpp // check for invalid select expressions template - struct is_valid_expression_t: public std::integral_constant::value or is_multi_column_t::value> {}; - using _valid_expressions = typename ::sqlpp::detail::make_set_if::type; - static_assert(_valid_expressions::size::value == sizeof...(NamedExpr), "at least one argument is not a named expression"); + using is_valid_expression_t = std::integral_constant::value or is_multi_column_t::value>; + static_assert(::sqlpp::detail::and_t::value, "at least one argument is not a named expression"); // check for duplicate select expression names static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate name detected"); diff --git a/include/sqlpp11/vendor/select_flag_list.h b/include/sqlpp11/vendor/select_flag_list.h index 14b1d978..a167e4fc 100644 --- a/include/sqlpp11/vendor/select_flag_list.h +++ b/include/sqlpp11/vendor/select_flag_list.h @@ -57,8 +57,7 @@ namespace sqlpp static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in select flag list"); // check for invalid order expressions - using _valid_flags = typename ::sqlpp::detail::make_set_if::type; - static_assert(_valid_flags::size::value == sizeof...(Flag), "at least one argument is not a select flag in select flag list"); + static_assert(::sqlpp::detail::and_t::value, "at least one argument is not a select flag in select flag list"); template void add(E expr) diff --git a/include/sqlpp11/vendor/update_list.h b/include/sqlpp11/vendor/update_list.h index 4cc70255..a58e92fd 100644 --- a/include/sqlpp11/vendor/update_list.h +++ b/include/sqlpp11/vendor/update_list.h @@ -50,12 +50,10 @@ namespace sqlpp static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in set()"); // check for invalid assignments - using _assignment_set = typename ::sqlpp::detail::make_set_if::type; - static_assert(_assignment_set::size::value == sizeof...(Assignments), "at least one argument is not an assignment in set()"); + static_assert(::sqlpp::detail::and_t::value, "at least one argument is not an assignment in set()"); // check for prohibited assignments - using _prohibited_assignment_set = typename ::sqlpp::detail::make_set_if::type; - static_assert(_prohibited_assignment_set::size::value == 0, "at least one assignment is prohibited by its column definition in set()"); + static_assert(not ::sqlpp::detail::or_t::value, "at least one assignment is prohibited by its column definition in set()"); template void add(Assignment assignment) diff --git a/include/sqlpp11/vendor/using.h b/include/sqlpp11/vendor/using.h index 24b7ba69..7f98b821 100644 --- a/include/sqlpp11/vendor/using.h +++ b/include/sqlpp11/vendor/using.h @@ -28,9 +28,9 @@ #define SQLPP_USING_H #include -#include #include #include +#include namespace sqlpp { @@ -49,8 +49,7 @@ namespace sqlpp static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in using()"); // check for invalid arguments - using _valid_expressions = typename ::sqlpp::detail::make_set_if::type; - static_assert(_valid_expressions::size::value == sizeof...(Table), "at least one argument is not an table in using()"); + static_assert(::sqlpp::detail::and_t::value, "at least one argument is not an table in using()"); template diff --git a/include/sqlpp11/vendor/where.h b/include/sqlpp11/vendor/where.h index 94d7a85c..72de65fa 100644 --- a/include/sqlpp11/vendor/where.h +++ b/include/sqlpp11/vendor/where.h @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include @@ -48,8 +48,7 @@ namespace sqlpp using _parameter_tuple_t = std::tuple; static_assert(_is_dynamic::value or sizeof...(Expr), "at least one expression argument required in where()"); - using _valid_expressions = typename sqlpp::detail::make_set_if::type; - static_assert(_valid_expressions::size::value == sizeof...(Expr), "at least one argument is not an expression in where()"); + static_assert(sqlpp::detail::and_t::value, "at least one argument is not an expression in where()"); using _parameter_list_t = typename make_parameter_list_t<_parameter_tuple_t>::type;