0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-15 20:31:16 +08:00

Use count instead of is_element_of

This commit is contained in:
rbock 2017-10-29 16:39:51 +01:00
parent f3b915cdc9
commit e1b82afbbe
7 changed files with 49 additions and 39 deletions

View File

@ -167,7 +167,7 @@ namespace sqlpp
using _parameters = parameters_of<Statement>; using _parameters = parameters_of<Statement>;
using _alias_t = typename AliasProvider::_alias_t; using _alias_t = typename AliasProvider::_alias_t;
constexpr static bool _is_recursive = detail::is_element_of<AliasProvider, required_ctes_of<Statement>>::value; constexpr static bool _is_recursive = required_ctes_of<Statement>::template count<AliasProvider>();
using _column_tuple_t = std::tuple<column_t<AliasProvider, cte_column_spec_t<FieldSpecs>>...>; using _column_tuple_t = std::tuple<column_t<AliasProvider, cte_column_spec_t<FieldSpecs>>...>;
@ -261,7 +261,7 @@ namespace sqlpp
{ {
static_assert(required_tables_of<Statement>::size::value == 0, static_assert(required_tables_of<Statement>::size::value == 0,
"common table expression must not use unknown tables"); "common table expression must not use unknown tables");
static_assert(not detail::is_element_of<AliasProvider, required_ctes_of<Statement>>::value, static_assert(not required_ctes_of<Statement>::template count<AliasProvider>(),
"common table expression must not self-reference in the first part, use union_all/union_distinct " "common table expression must not self-reference in the first part, use union_all/union_distinct "
"for recursion"); "for recursion");
static_assert(is_static_result_row_t<get_result_row_t<Statement>>::value, static_assert(is_static_result_row_t<get_result_row_t<Statement>>::value,

View File

@ -45,29 +45,41 @@ namespace sqlpp
template <typename E, typename SET> template <typename E, typename SET>
struct is_element_of; struct is_element_of;
template <typename T>
struct _base
{
};
// A type set // A type set
template <typename... Elements> template <typename... Elements>
struct type_set struct type_set
{ {
private:
struct _impl : _base<Elements>...
{
};
public:
using size = std::integral_constant<size_t, sizeof...(Elements)>; using size = std::integral_constant<size_t, sizeof...(Elements)>;
using _is_type_set = std::true_type; using _is_type_set = std::true_type;
static_assert(std::is_same<type_set, make_type_set_t<Elements...>>::value, template <typename T>
"use make_type_set to construct a typeset"); static constexpr bool count()
{
return std::is_base_of<_base<T>, _impl>::value;
}
template <typename T> template <typename T>
struct insert struct insert
{ {
using type = using type = typename std::conditional<count<T>(), type_set, type_set<T, Elements...>>::type;
typename std::conditional<not is_element_of<T, type_set>::value, type_set<T, Elements...>, type_set>::type;
}; };
template <template <typename A> class Predicate, typename T> template <template <typename A> class Predicate, typename T>
struct insert_if struct insert_if
{ {
using type = typename std::conditional<Predicate<T>::value and not is_element_of<T, type_set>::value, using type =
type_set<Elements..., T>, typename std::conditional<Predicate<T>::value and not count<T>(), type_set<Elements..., T>, type_set>::type;
type_set>::type;
}; };
}; };
@ -80,7 +92,7 @@ namespace sqlpp
template <typename E, typename... Elements> template <typename E, typename... Elements>
struct is_element_of<E, type_set<Elements...>> struct is_element_of<E, type_set<Elements...>>
{ {
static constexpr bool value = ::sqlpp::logic::any_t<std::is_same<E, Elements>::value...>::value; static constexpr bool value = type_set<Elements...>::template count<E>();
}; };
template <typename L, typename R> template <typename L, typename R>
@ -224,8 +236,8 @@ namespace sqlpp
struct make_intersect_set<type_set<LhsElements...>, type_set<RhsElements...>> struct make_intersect_set<type_set<LhsElements...>, type_set<RhsElements...>>
{ {
template <typename E> template <typename E>
using is_in_both = ::sqlpp::logic::all_t<is_element_of<E, type_set<LhsElements...>>::value, using is_in_both = ::sqlpp::logic::all_t<type_set<LhsElements...>::template count<E>(),
is_element_of<E, type_set<RhsElements...>>::value>; type_set<RhsElements...>::template count<E>()>;
using type = make_type_set_if_t<is_in_both, LhsElements...>; using type = make_type_set_if_t<is_in_both, LhsElements...>;
}; };

View File

@ -256,7 +256,7 @@ namespace sqlpp
static_assert(_is_dynamic::value, "add must not be called for static from()"); static_assert(_is_dynamic::value, "add must not be called for static from()");
static_assert(is_assignment_t<Assignment>::value, "add() arguments require to be assigments"); static_assert(is_assignment_t<Assignment>::value, "add() arguments require to be assigments");
using _assigned_columns = detail::make_type_set_t<lhs_t<Assignments>...>; using _assigned_columns = detail::make_type_set_t<lhs_t<Assignments>...>;
static_assert(not detail::is_element_of<lhs_t<Assignment>, _assigned_columns>::value, static_assert(not _assigned_columns::template count<lhs_t<Assignment>>(),
"Must not assign value to column twice"); "Must not assign value to column twice");
static_assert(not must_not_insert_t<lhs_t<Assignment>>::value, "add() argument must not be used in insert"); static_assert(not must_not_insert_t<lhs_t<Assignment>>::value, "add() argument must not be used in insert");
static_assert(Policies::template _no_unknown_tables<Assignment>::value, static_assert(Policies::template _no_unknown_tables<Assignment>::value,

View File

@ -132,7 +132,7 @@ namespace sqlpp
static_assert(Policies::template _no_unknown_tables<named_expression>::value, static_assert(Policies::template _no_unknown_tables<named_expression>::value,
"named expression uses tables unknown to this statement in selected_columns::add()"); "named expression uses tables unknown to this statement in selected_columns::add()");
using column_names = detail::make_type_set_t<typename Columns::_alias_t...>; using column_names = detail::make_type_set_t<typename Columns::_alias_t...>;
static_assert(not detail::is_element_of<typename named_expression::_alias_t, column_names>::value, static_assert(not column_names::template count<typename named_expression::_alias_t>(),
"a column of this name is present in the select already"); "a column of this name is present in the select already");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, named_expression>; using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, named_expression>;
_serialize_check{}; _serialize_check{};

View File

@ -69,7 +69,7 @@ namespace sqlpp
template <typename Needle, typename Replacement> template <typename Needle, typename Replacement>
struct _policies_update_t struct _policies_update_t
{ {
static_assert(detail::is_element_of<Needle, make_type_set_t<Policies...>>::value, static_assert(make_type_set_t<Policies...>::template count<Needle>(),
"policies update for non-policy class detected"); "policies update for non-policy class detected");
using type = statement_t<Db, policy_update_t<Policies, Needle, Replacement>...>; using type = statement_t<Db, policy_update_t<Policies, Needle, Replacement>...>;
}; };

View File

@ -124,7 +124,7 @@ namespace sqlpp
template <typename T> template <typename T>
struct column_spec_can_be_null_impl< struct column_spec_can_be_null_impl<
T, T,
typename std::enable_if<detail::is_element_of<tag::can_be_null, typename T::_traits::_tags>::value>::type> typename std::enable_if<T::_traits::_tags::template count<tag::can_be_null>()>::type>
{ {
using type = std::true_type; using type = std::true_type;
}; };
@ -132,27 +132,25 @@ namespace sqlpp
template <typename T> template <typename T>
using column_spec_can_be_null_t = typename detail::column_spec_can_be_null_impl<T>::type; using column_spec_can_be_null_t = typename detail::column_spec_can_be_null_impl<T>::type;
#define SQLPP_VALUE_TRAIT_GENERATOR(name) \ #define SQLPP_VALUE_TRAIT_GENERATOR(name) \
namespace tag \ namespace tag \
{ \ { \
struct name; \ struct name; \
} \ } \
namespace detail \ namespace detail \
{ \ { \
template <typename T, typename Enable = void> \ template <typename T, typename Enable = void> \
struct name##_impl \ struct name##_impl \
{ \ { \
using type = std::false_type; \ using type = std::false_type; \
}; \ }; \
template <typename T> \ template <typename T> \
struct name##_impl< \ struct name##_impl<T, typename std::enable_if<T::_traits::_tags::template count<tag::name>()>::type> \
T, \ { \
typename std::enable_if<detail::is_element_of<tag::name, typename T::_traits::_tags>::value>::type> \ using type = std::true_type; \
{ \ }; \
using type = std::true_type; \ } \
}; \ template <typename T> \
} \
template <typename T> \
using name##_t = typename detail::name##_impl<T>::type; using name##_t = typename detail::name##_impl<T>::type;
SQLPP_VALUE_TRAIT_GENERATOR(is_sql_null) SQLPP_VALUE_TRAIT_GENERATOR(is_sql_null)
@ -326,7 +324,7 @@ namespace sqlpp
template <typename KnownAggregates, typename T> template <typename KnownAggregates, typename T>
struct is_aggregate_expression_impl<KnownAggregates, struct is_aggregate_expression_impl<KnownAggregates,
T, T,
typename std::enable_if<detail::is_element_of<T, KnownAggregates>::value>::type> typename std::enable_if<KnownAggregates::template count<T>()>::type>
{ {
using type = std::true_type; using type = std::true_type;
}; };

View File

@ -83,7 +83,7 @@ namespace sqlpp
static_assert(_is_dynamic::value, "add must not be called for static from()"); static_assert(_is_dynamic::value, "add must not be called for static from()");
static_assert(is_assignment_t<Assignment>::value, "invalid assignment argument in add()"); static_assert(is_assignment_t<Assignment>::value, "invalid assignment argument in add()");
using _assigned_columns = detail::make_type_set_t<lhs_t<Assignments>...>; using _assigned_columns = detail::make_type_set_t<lhs_t<Assignments>...>;
static_assert(not detail::is_element_of<lhs_t<Assignment>, _assigned_columns>::value, static_assert(not _assigned_columns::template count<lhs_t<Assignment>>(),
"Must not assign value to column twice"); "Must not assign value to column twice");
static_assert(logic::not_t<must_not_update_t, lhs_t<Assignment>>::value, "add() argument must not be updated"); static_assert(logic::not_t<must_not_update_t, lhs_t<Assignment>>::value, "add() argument must not be updated");
static_assert(Policies::template _no_unknown_tables<Assignment>::value, static_assert(Policies::template _no_unknown_tables<Assignment>::value,