0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 04:47:18 +08:00

Rewrote all_t to use bool arguments instead of predicate and classes

This commit is contained in:
rbock 2014-05-01 17:34:47 +02:00
parent 2452f224d4
commit 331353022a
17 changed files with 62 additions and 64 deletions

View File

@ -134,14 +134,14 @@ namespace sqlpp
template<typename... T>
vendor::in_t<true, Base, vendor::wrap_operand_t<T>...> in(T... t) const
{
static_assert(detail::all_t<_is_valid_comparison_operand, vendor::wrap_operand_t<T>...>::value, "at least one operand of in() is not valid");
static_assert(detail::all_t<_is_valid_comparison_operand<vendor::wrap_operand_t<T>>::value...>::value, "at least one operand of in() is not valid");
return { *static_cast<const Base*>(this), vendor::wrap_operand_t<T>{t}... };
}
template<typename... T>
vendor::in_t<false, Base, vendor::wrap_operand_t<T>...> not_in(T... t) const
{
static_assert(detail::all_t<_is_valid_comparison_operand, vendor::wrap_operand_t<T>...>::value, "at least one operand of in() is not valid");
static_assert(detail::all_t<_is_valid_comparison_operand<vendor::wrap_operand_t<T>>::value...>::value, "at least one operand of in() is not valid");
return { *static_cast<const Base*>(this), vendor::wrap_operand_t<T>{t}... };
}

View File

@ -36,10 +36,10 @@ namespace sqlpp
template<bool... B>
struct logic_helper;
template<template<typename> class Predicate, typename... T>
template<bool... B>
using all_t = std::integral_constant<
bool,
std::is_same<logic_helper<Predicate<T>::value...>, logic_helper<(true or Predicate<T>::value)...>>::value>;
std::is_same<logic_helper<B...>, logic_helper<(true or B)...>>::value>;
template<bool... B>
using any_t = std::integral_constant<

View File

@ -82,26 +82,6 @@ namespace sqlpp
static constexpr bool value = any_t<std::is_same<E, Elements>::value...>::value;
};
template<typename L, typename R>
struct is_superset_of
{
static_assert(::sqlpp::vendor::wrong_t<L, R>::value, "L and R have to be type sets");
};
template<typename... LElements, typename... RElements>
struct is_superset_of<type_set<LElements...>, type_set<RElements...>>
{
template<typename X>
using is_element_of_L = is_element_of<X, type_set<LElements...>>;
static constexpr bool value = all_t<is_element_of_L, RElements...>::value;
};
template<typename L, typename R>
struct is_subset_of
{
static constexpr bool value = is_superset_of<R, L>::value;
};
template<typename L, typename R>
struct joined_set
{
@ -117,6 +97,24 @@ namespace sqlpp
template<typename L, typename R>
using joined_set_t = typename joined_set<L, R>::type;
template<typename L, typename R>
struct is_superset_of
{
static_assert(::sqlpp::vendor::wrong_t<L, R>::value, "L and R have to be type sets");
};
template<typename... LElements, typename... RElements>
struct is_superset_of<type_set<LElements...>, type_set<RElements...>>
{
static constexpr bool value = joined_set_t<type_set<LElements...>, type_set<RElements...>>::size::value == sizeof...(LElements);
};
template<typename L, typename R>
struct is_subset_of
{
static constexpr bool value = is_superset_of<R, L>::value;
};
template<typename L, typename R>
struct is_disjunct_from
{

View File

@ -41,7 +41,7 @@ namespace sqlpp
template<typename Unused, typename... Columns>
struct multi_column_t
{
static_assert(detail::all_t<is_named_expression_t, Columns...>::value, "multi_column parameters need to be named expressions");
static_assert(detail::all_t<is_named_expression_t<Columns>::value...>::value, "multi_column parameters need to be named expressions");
using _table_set = sqlpp::detail::make_joined_set_t<typename Columns::_table_set...>;
@ -75,7 +75,7 @@ namespace sqlpp
template<typename AliasProvider, typename... Columns>
struct multi_column_alias_t
{
static_assert(detail::all_t<is_named_expression_t, Columns...>::value, "multi_column parameters need to be named expressions");
static_assert(detail::all_t<is_named_expression_t<Columns>::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<typename Columns::_table_set...>;

View File

@ -41,7 +41,7 @@ namespace sqlpp
using _is_dynamic = typename std::conditional<std::is_same<Database, void>::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<is_expression_t, Expr...>::value, "at least one argument is not an expression in on()");
static_assert(detail::all_t<is_expression_t<Expr>::value...>::value, "at least one argument is not an expression in on()");
template<typename E>
void add(E expr)

View File

@ -39,7 +39,7 @@ namespace sqlpp
struct concat_t: public First::_value_type::template expression_operators<concat_t<First, Args...>>
{
static_assert(sizeof...(Args) > 0, "concat requires two arguments at least");
static_assert(sqlpp::detail::all_t<is_text_t, First, Args...>::value, "at least one non-text argument detected in concat()");
static_assert(sqlpp::detail::all_t<is_text_t<First>::value, is_text_t<Args>::value...>::value, "at least one non-text argument detected in concat()");
using _table_set = typename ::sqlpp::detail::make_joined_set<typename First::_table_set, typename Args::_table_set...>::type;
struct _value_type: public First::_value_type::_base_value_type

View File

@ -45,7 +45,7 @@ namespace sqlpp
static_assert(not ::sqlpp::detail::has_duplicates<Tables...>::value, "at least one duplicate argument detected in extra_tables()");
static_assert(::sqlpp::detail::all_t<is_table_t, Tables...>::value, "at least one argument is not a table or join in extra_tables()");
static_assert(::sqlpp::detail::all_t<is_table_t<Tables>::value...>::value, "at least one argument is not a table or join in extra_tables()");
using _table_set = ::sqlpp::detail::make_joined_set_t<typename Tables::_table_set...>;

View File

@ -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<Tables...>::value, "at least one duplicate argument detected in from()");
static_assert(::sqlpp::detail::all_t<is_table_t, Tables...>::value, "at least one argument is not a table or join in from()");
static_assert(::sqlpp::detail::all_t<is_table_t<Tables>::value...>::value, "at least one argument is not a table or join in from()");
using _table_set = ::sqlpp::detail::make_joined_set_t<typename Tables::_table_set...>;
@ -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<Table>::value, "invalid table argument in add_from()");
using ok = ::sqlpp::detail::all_t<sqlpp::detail::identity_t, _is_dynamic, is_table_t<Table>>;
using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_table_t<Table>::value>;
_add_from_impl(table, ok()); // dispatch to prevent compile messages after the static_assert
}

View File

@ -54,7 +54,7 @@ namespace sqlpp
static_assert(not ::sqlpp::detail::has_duplicates<Expressions...>::value, "at least one duplicate argument detected in group_by()");
static_assert(::sqlpp::detail::all_t<is_expression_t, Expressions...>::value, "at least one argument is not an expression in group_by()");
static_assert(::sqlpp::detail::all_t<is_expression_t<Expressions>::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<Expression>::value, "invalid expression argument in add_group_by()");
static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables<Expression>::value, "expression uses tables unknown to this statement in add_group_by()");
using ok = ::sqlpp::detail::all_t<sqlpp::detail::identity_t, _is_dynamic, is_expression_t<Expression>>;
using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t<Expression>::value>;
_add_group_by_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
}

View File

@ -47,7 +47,7 @@ namespace sqlpp
using _parameter_tuple_t = std::tuple<Expressions...>;
static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression argument required in having()");
static_assert(::sqlpp::detail::all_t<is_expression_t, Expressions...>::value, "at least one argument is not an expression in having()");
static_assert(::sqlpp::detail::all_t<is_expression_t<Expressions>::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<Expression>::value, "invalid expression argument in add_having()");
static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables<Expression>::value, "expression uses tables unknown to this statement in add_having()");
using ok = ::sqlpp::detail::all_t<sqlpp::detail::identity_t, _is_dynamic, is_expression_t<Expression>>;
using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t<Expression>::value>;
_add_having_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
}

View File

@ -65,7 +65,7 @@ namespace sqlpp
static_assert(not ::sqlpp::detail::has_duplicates<Assignments...>::value, "at least one duplicate argument detected in set()");
static_assert(sqlpp::detail::all_t<is_assignment_t, Assignments...>::value, "at least one argument is not an assignment in set()");
static_assert(sqlpp::detail::all_t<is_assignment_t<Assignments>::value...>::value, "at least one argument is not an assignment in set()");
static_assert(sqlpp::detail::none_t<must_not_insert_t<typename Assignments::_column_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::identity_t,
_is_dynamic,
is_assignment_t<Assignment>,
::sqlpp::detail::not_t<must_not_insert_t, typename Assignment::_column_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<Assignment>::value,
not must_not_insert_t<typename Assignment::_column_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<Columns...>::value, "at least one duplicate argument detected in columns()");
static_assert(::sqlpp::detail::all_t<is_column_t, Columns...>::value, "at least one argument is not a column in columns()");
static_assert(::sqlpp::detail::all_t<is_column_t<Columns>::value...>::value, "at least one argument is not a column in columns()");
static_assert(::sqlpp::detail::none_t<must_not_insert_t<Columns>::value...>::value, "at least one column argument has a must_not_insert flag in its definition");
@ -167,14 +167,14 @@ namespace sqlpp
template<typename... Assignments>
void add_values(Assignments... assignments)
{
static_assert(::sqlpp::detail::all_t<is_assignment_t, Assignments...>::value, "add_values() arguments have to be assignments");
static_assert(::sqlpp::detail::all_t<is_assignment_t<Assignments>::value...>::value, "add_values() arguments have to be assignments");
using _arg_value_tuple = std::tuple<vendor::insert_value_t<typename Assignments::_column_t>...>;
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<sqlpp::detail::identity_t,
::sqlpp::detail::all_t<is_assignment_t, Assignments...>,
_args_correct>;
using ok = ::sqlpp::detail::all_t<
::sqlpp::detail::all_t<is_assignment_t<Assignments>::value...>::value,
_args_correct::value>;
_add_values_impl(ok(), assignments...); // dispatch to prevent compile messages after the static_assert
}

View File

@ -53,7 +53,7 @@ namespace sqlpp
static_assert(not ::sqlpp::detail::has_duplicates<Expressions...>::value, "at least one duplicate argument detected in order_by()");
static_assert(::sqlpp::detail::all_t<is_sort_order_t, Expressions...>::value, "at least one argument is not a sort order expression in order_by()");
static_assert(::sqlpp::detail::all_t<is_sort_order_t<Expressions>::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<Expression>::value, "invalid expression argument in add_order_by()");
static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables<Expression>::value, "expression uses tables unknown to this statement in add_order_by()");
using ok = ::sqlpp::detail::all_t<sqlpp::detail::identity_t, _is_dynamic, is_sort_order_t<Expression>>;
using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_sort_order_t<Expression>::value>;
_add_order_by_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
}

View File

@ -143,7 +143,7 @@ namespace sqlpp
template<typename T>
using is_valid_expression_t = std::integral_constant<bool, is_named_expression_t<T>::value or is_multi_column_t<T>::value>;
static_assert(::sqlpp::detail::all_t<is_valid_expression_t, Columns...>::value, "at least one argument is not a named expression");
static_assert(::sqlpp::detail::all_t<is_valid_expression_t<Columns>::value...>::value, "at least one argument is not a named expression");
static_assert(not ::sqlpp::detail::has_duplicates<typename Columns::_name_t...>::value, "at least one duplicate name detected");
@ -206,9 +206,9 @@ namespace sqlpp
using column_names = ::sqlpp::detail::make_type_set_t<typename Columns::_name_t...>;
static_assert(not ::sqlpp::detail::is_element_of<typename NamedExpression::_name_t, column_names>::value, "a column of this name is present in the select already");
using ok = ::sqlpp::detail::all_t<sqlpp::detail::identity_t,
_is_dynamic,
is_named_expression_t<NamedExpression>
using ok = ::sqlpp::detail::all_t<
_is_dynamic::value,
is_named_expression_t<NamedExpression>::value
>;
_add_column_impl(namedExpression, ok()); // dispatch to prevent compile messages after the static_assert

View File

@ -50,7 +50,7 @@ namespace sqlpp
static_assert(not ::sqlpp::detail::has_duplicates<Flags...>::value, "at least one duplicate argument detected in select flag list");
static_assert(::sqlpp::detail::all_t<is_select_flag_t, Flags...>::value, "at least one argument is not a select flag in select flag list");
static_assert(::sqlpp::detail::all_t<is_select_flag_t<Flags>::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<Flag>::value, "invalid select flag argument in add_flag()");
static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables<Flag>::value, "flag uses tables unknown to this statement in add_flag()");
using ok = ::sqlpp::detail::all_t<sqlpp::detail::identity_t, _is_dynamic, is_select_flag_t<Flag>>;
using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_select_flag_t<Flag>::value>;
_add_flag_impl(flag, ok()); // dispatch to prevent compile messages after the static_assert
}

View File

@ -48,7 +48,7 @@ namespace sqlpp
static_assert(not ::sqlpp::detail::has_duplicates<Assignments...>::value, "at least one duplicate argument detected in set()");
static_assert(::sqlpp::detail::all_t<is_assignment_t, Assignments...>::value, "at least one argument is not an assignment in set()");
static_assert(::sqlpp::detail::all_t<is_assignment_t<Assignments>::value...>::value, "at least one argument is not an assignment in set()");
static_assert(::sqlpp::detail::none_t<must_not_update_t<typename Assignments::_column_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<must_not_update_t, typename Assignment::_column_t>::value, "add_set() argument must not be updated");
static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables<Assignment>::value, "assignment uses tables unknown to this statement in add_set()");
using ok = ::sqlpp::detail::all_t<sqlpp::detail::identity_t,
_is_dynamic,
is_assignment_t<Assignment>,
sqlpp::detail::not_t<must_not_update_t, typename Assignment::_column_t>>;
using ok = ::sqlpp::detail::all_t<
_is_dynamic::value,
is_assignment_t<Assignment>::value,
not must_not_update_t<typename Assignment::_column_t>::value>;
_add_set_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert
}

View File

@ -49,7 +49,7 @@ namespace sqlpp
static_assert(not ::sqlpp::detail::has_duplicates<Tables...>::value, "at least one duplicate argument detected in using()");
static_assert(::sqlpp::detail::all_t<is_table_t, Tables...>::value, "at least one argument is not an table in using()");
static_assert(::sqlpp::detail::all_t<is_table_t<Tables>::value...>::value, "at least one argument is not an table in using()");
using _table_set = ::sqlpp::detail::make_joined_set_t<typename Tables::_table_set...>;
@ -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<Table>::value, "invalid table argument in add_using()");
using ok = ::sqlpp::detail::all_t<sqlpp::detail::identity_t, _is_dynamic, is_table_t<Table>>;
using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_table_t<Table>::value>;
_add_using_impl(table, ok()); // dispatch to prevent compile messages after the static_assert
}

View File

@ -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<is_assignment_t<Expressions>::value...>::value, "at least one argument is an assignment in where()");
static_assert(sqlpp::detail::all_t<is_expression_t, Expressions...>::value, "at least one argument is not valid expression in where()");
static_assert(sqlpp::detail::all_t<is_expression_t<Expressions>::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<Expression>::value, "invalid expression argument in add_where()");
static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables<Expression>::value, "expression uses tables unknown to this statement in add_where()");
using ok = ::sqlpp::detail::all_t<sqlpp::detail::identity_t, _is_dynamic, is_expression_t<Expression>>;
using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t<Expression>::value>;
_add_where_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
}