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

Replaced a bunch of make_set_if::size asserts with and_t/or_t

This commit is contained in:
rbock 2014-02-02 18:45:21 +01:00
parent 14c382db59
commit e1f619eecb
16 changed files with 53 additions and 112 deletions

View File

@ -29,49 +29,27 @@
#include <type_traits>
#include <sqlpp11/vendor/wrong.h>
#include <sqlpp11/detail/logic.h>
namespace sqlpp
{
namespace detail
{
// some forward declarations and helpers
template<typename... T>
struct make_set;
template<typename T>
class type_set_element {};
template<typename SET, typename... T>
struct is_superset_of_impl
: std::false_type {};
template<typename SET>
struct is_superset_of_impl<SET>
: std::true_type {};
template<typename SET, typename T, typename... Rest>
struct is_superset_of_impl<SET, T, Rest...>
: std::integral_constant<bool, SET::template contains<T>::value and is_superset_of_impl<SET, Rest...>::value> {};
template<typename SET, typename... T>
struct is_disjunct_from_impl
: std::false_type {};
template<typename SET>
struct is_disjunct_from_impl<SET>
: std::true_type {};
template<typename SET, typename T, typename... Rest>
struct is_disjunct_from_impl<SET, T, Rest...>
: std::integral_constant<bool, not SET::template contains<T>::value and is_disjunct_from_impl<SET, Rest...>::value> {};
// A type set
template<typename... Element>
struct type_set: type_set_element<Element>...
{
struct size: std::integral_constant<size_t, sizeof...(Element)> {};
using size = std::integral_constant<size_t, sizeof...(Element)>;
template<typename T>
struct contains
: std::integral_constant<bool, std::is_base_of<type_set_element<T>, type_set>::value> {};
using count = std::is_base_of<type_set_element<T>, type_set>;
template<typename T>
struct is_superset_of
@ -81,7 +59,7 @@ namespace sqlpp
template<typename... T>
struct is_superset_of<type_set<T...>>
: is_superset_of_impl<type_set, T...>{};
: and_t<count, T...> {};
template<typename T>
struct join
@ -93,16 +71,6 @@ namespace sqlpp
struct join<type_set<T...>>
: make_set<Element..., T...> {};
template<typename T>
struct is_disjunct_from
{
static_assert(::sqlpp::vendor::wrong_t<T>::value, "invalid argument for is_disjunct_from");
};
template<typename... T>
struct is_disjunct_from<type_set<T...>>
: is_disjunct_from_impl<type_set, T...>{};
template<typename T>
struct is_subset_of
{
@ -111,20 +79,19 @@ namespace sqlpp
template<typename... T>
struct is_subset_of<type_set<T...>>
: is_superset_of_impl<type_set<T...>, Element...>{};
: type_set<T...>::template is_superset_of<type_set>{};
template<typename T>
struct equals
struct is_disjunct_from
{
static_assert(::sqlpp::vendor::wrong_t<T>::value, "invalid argument for equals");
static_assert(::sqlpp::vendor::wrong_t<T>::value, "invalid argument for is_disjunct_from");
};
template<typename... T>
struct equals<type_set<T...>>
: std::integral_constant<bool,
is_superset_of_impl<type_set<T...>, Element...>::value
and
is_superset_of_impl<type_set<Element...>, T...>::value> {};
struct is_disjunct_from<type_set<T...>>
{
static constexpr bool value = not(or_t<type_set::count, T...>::value or or_t<type_set<T...>::template count, Element...>::value);
};
template<typename T, typename Enable = void>
struct insert
@ -133,23 +100,18 @@ namespace sqlpp
};
template<typename T>
struct insert<T, typename std::enable_if<not type_set::template contains<T>::value>::type>
struct insert<T, typename std::enable_if<not type_set::template count<T>::value>::type>
{
using type = type_set<Element..., T>;
};
template<template<typename A> class Predicate, typename T, typename Enable = void>
struct insert_if
{
using type = type_set;
};
template<template<typename A> class Predicate, typename T>
struct insert_if<Predicate, T, typename std::enable_if<not type_set::template contains<T>::value and Predicate<T>::value>::type>
struct insert_if
{
using type = type_set<Element..., T>;
using type = typename std::conditional<Predicate<T>::value,
type_set<Element..., T>,
type_set>::type;
};
};
template<>
@ -182,17 +144,13 @@ namespace sqlpp
template<template<typename> class Predicate, typename... T>
struct make_set_if_not
{
template<typename A>
struct InversePredicate
{
static constexpr bool value = not Predicate<A>::value;
};
template<typename X>
using InversePredicate = std::integral_constant<bool, not Predicate<X>::value>;
using type = typename make_set_if<InversePredicate, T...>::type;
};
template<typename... T>
struct has_duplicates
: std::integral_constant<bool, make_set<T...>::type::size::value != sizeof...(T)> {};
using has_duplicates = std::integral_constant<bool, make_set<T...>::type::size::value != sizeof...(T)>;
}
}

View File

@ -27,8 +27,9 @@
#ifndef SQLPP_MULTI_COLUMN_H
#define SQLPP_MULTI_COLUMN_H
#include <sqlpp11/detail/make_expression_tuple.h>
#include <sqlpp11/no_value.h>
#include <sqlpp11/detail/make_expression_tuple.h>
#include <sqlpp11/detail/logic.h>
namespace sqlpp
{
@ -41,8 +42,7 @@ namespace sqlpp
template<typename AliasProvider, typename... NamedExpr>
struct multi_column_t<AliasProvider, std::tuple<NamedExpr...>>
{
using _named_expr_set = typename detail::make_set_if<is_named_expression_t, NamedExpr...>::type;
static_assert(_named_expr_set::size::value == sizeof...(NamedExpr), "multi_column parameters need to be named expressions");
static_assert(detail::and_t<is_named_expression_t, NamedExpr...>::value, "multi_column parameters need to be named expressions");
using _name_t = typename AliasProvider::_name_t;

View File

@ -28,9 +28,9 @@
#define SQLPP_ON_H
#include <sqlpp11/type_traits.h>
#include <sqlpp11/detail/type_set.h>
#include <sqlpp11/vendor/interpret_tuple.h>
#include <sqlpp11/vendor/interpretable_list.h>
#include <sqlpp11/detail/logic.h>
namespace sqlpp
{
@ -41,8 +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()");
using _valid_expressions = typename detail::make_set_if<is_expression_t, Expr...>::type;
static_assert(_valid_expressions::size::value == sizeof...(Expr), "at least one argument is not an expression in on()");
static_assert(detail::and_t<is_expression_t, Expr...>::value, "at least one argument is not an expression in on()");
template<typename E>
void add(E expr)

View File

@ -28,7 +28,7 @@
#define SQLPP_COLUMN_LIST_H
#include <sqlpp11/type_traits.h>
#include <sqlpp11/detail/type_set.h>
#include <sqlpp11/detail/logic.h>
#include <sqlpp11/vendor/interpret_tuple.h>
#include <sqlpp11/vendor/simple_column.h>
@ -49,12 +49,10 @@ namespace sqlpp
static_assert(not ::sqlpp::detail::has_duplicates<Columns...>::value, "at least one duplicate argument detected in columns()");
// check for invalid columns
using _column_set = typename ::sqlpp::detail::make_set_if<is_column_t, Columns...>::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<is_column_t, Columns...>::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<must_not_insert_t, Columns...>::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<must_not_insert_t, Columns...>::value, "at least one column argument has a must_not_insert flag in its definition");
std::tuple<simple_column_t<Columns>...> _columns;
};

View File

@ -29,7 +29,7 @@
#include <sqlpp11/type_traits.h>
#include <sqlpp11/vendor/interpret_tuple.h>
#include <sqlpp11/detail/type_set.h>
#include <sqlpp11/detail/logic.h>
namespace sqlpp
{
@ -39,8 +39,7 @@ namespace sqlpp
struct concat_t: public First::_value_type::template operators<concat_t<First, Args...>>
{
static_assert(sizeof...(Args) > 0, "concat requires two arguments at least");
using _valid_args = typename ::sqlpp::detail::make_set_if_not<is_text_t, First, Args...>::type;
static_assert(_valid_args::size::value == 0, "at least one non-text argument detected in concat()");
static_assert(sqlpp::detail::and_t<is_text_t, First, Args...>::value, "at least one non-text argument detected in concat()");
struct _value_type: public First::_value_type::_base_value_type
{

View File

@ -27,11 +27,11 @@
#ifndef SQLPP_FROM_H
#define SQLPP_FROM_H
#include <ostream>
#include <sqlpp11/select_fwd.h>
#include <sqlpp11/type_traits.h>
#include <sqlpp11/vendor/interpretable_list.h>
#include <sqlpp11/vendor/interpret_tuple.h>
#include <sqlpp11/detail/logic.h>
namespace sqlpp
{
@ -50,8 +50,7 @@ namespace sqlpp
static_assert(not ::sqlpp::detail::has_duplicates<TableOrJoin...>::value, "at least one duplicate argument detected in from()");
// check for invalid arguments
using _valid_expressions = typename ::sqlpp::detail::make_set_if<is_table_t, TableOrJoin...>::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<is_table_t, TableOrJoin...>::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

View File

@ -32,7 +32,7 @@
#include <sqlpp11/vendor/expression.h>
#include <sqlpp11/vendor/interpret_tuple.h>
#include <sqlpp11/vendor/interpretable_list.h>
#include <sqlpp11/detail/type_set.h>
#include <sqlpp11/detail/logic.h>
namespace sqlpp
{
@ -52,8 +52,7 @@ namespace sqlpp
static_assert(not ::sqlpp::detail::has_duplicates<Expr...>::value, "at least one duplicate argument detected in group_by()");
// check for invalid expressions
using _valid_expressions = typename ::sqlpp::detail::make_set_if<is_expression_t, Expr...>::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<is_expression_t, Expr...>::value, "at least one argument is not an expression in group_by()");
template<typename E>
void add(E expr)

View File

@ -31,7 +31,7 @@
#include <sqlpp11/vendor/expression.h>
#include <sqlpp11/vendor/interpret_tuple.h>
#include <sqlpp11/vendor/interpretable_list.h>
#include <sqlpp11/detail/type_set.h>
#include <sqlpp11/detail/logic.h>
namespace sqlpp
{
@ -45,8 +45,7 @@ namespace sqlpp
using _parameter_tuple_t = std::tuple<Expr...>;
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<is_expression_t, Expr...>::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<is_expression_t, Expr...>::value, "at least one argument is not an expression in having()");
using _parameter_list_t = typename make_parameter_list_t<_parameter_tuple_t>::type;

View File

@ -28,10 +28,10 @@
#define SQLPP_INSERT_LIST_H
#include <sqlpp11/type_traits.h>
#include <sqlpp11/detail/type_set.h>
#include <sqlpp11/vendor/interpret_tuple.h>
#include <sqlpp11/vendor/interpretable_list.h>
#include <sqlpp11/vendor/simple_column.h>
#include <sqlpp11/detail/logic.h>
namespace sqlpp
{
@ -69,12 +69,10 @@ namespace sqlpp
static_assert(not ::sqlpp::detail::has_duplicates<Assignments...>::value, "at least one duplicate argument detected in set()");
// check for invalid assignments
using _assignment_set = typename ::sqlpp::detail::make_set_if<is_assignment_t, Assignments...>::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<is_assignment_t, Assignments...>::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<must_not_insert_t, typename Assignments::_column_t...>::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<must_not_insert_t, typename Assignments::_column_t...>::value, "at least one assignment is prohibited by its column definition in set()");
insert_list_t(Assignments... assignment):
_columns({assignment._lhs}...),

View File

@ -28,7 +28,7 @@
#define SQLPP_INSERT_VALUE_LIST_H
#include <sqlpp11/type_traits.h>
#include <sqlpp11/detail/type_set.h>
#include <sqlpp11/detail/logic.h>
#include <sqlpp11/vendor/insert_value.h>
#include <sqlpp11/vendor/interpret_tuple.h>
@ -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<is_insert_value_t, InsertValues...>::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<is_insert_value_t, InsertValues...>::value, "at least one argument is not an insert value");
using _value_tuple_t = std::tuple<InsertValues...>;

View File

@ -51,8 +51,7 @@ namespace sqlpp
static_assert(not ::sqlpp::detail::has_duplicates<Expr...>::value, "at least one duplicate argument detected in order_by()");
// check for invalid order expressions
using _valid_expressions = typename ::sqlpp::detail::make_set_if<is_sort_order_t, Expr...>::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<is_sort_order_t, Expr...>::value, "at least one argument is not a sort order expression in order_by()");
template<typename E>
void add(E expr)

View File

@ -31,9 +31,9 @@
#include <sqlpp11/result_row.h>
#include <sqlpp11/select_fwd.h>
#include <sqlpp11/table.h>
#include <sqlpp11/vendor/expression_fwd.h>
#include <sqlpp11/no_value.h>
#include <sqlpp11/vendor/field.h>
#include <sqlpp11/vendor/expression_fwd.h>
#include <sqlpp11/vendor/select_pseudo_table.h>
#include <sqlpp11/vendor/named_interpretable.h>
#include <sqlpp11/vendor/interpret_tuple.h>
@ -149,9 +149,8 @@ namespace sqlpp
// check for invalid select expressions
template<typename T>
struct is_valid_expression_t: public std::integral_constant<bool, is_named_expression_t<T>::value or is_multi_column_t<T>::value> {};
using _valid_expressions = typename ::sqlpp::detail::make_set_if<is_valid_expression_t, NamedExpr...>::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<bool, is_named_expression_t<T>::value or is_multi_column_t<T>::value>;
static_assert(::sqlpp::detail::and_t<is_valid_expression_t, NamedExpr...>::value, "at least one argument is not a named expression");
// check for duplicate select expression names
static_assert(not ::sqlpp::detail::has_duplicates<typename NamedExpr::_name_t...>::value, "at least one duplicate name detected");

View File

@ -57,8 +57,7 @@ namespace sqlpp
static_assert(not ::sqlpp::detail::has_duplicates<Flag...>::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<is_select_flag_t, Flag...>::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<is_select_flag_t, Flag...>::value, "at least one argument is not a select flag in select flag list");
template<typename E>
void add(E expr)

View File

@ -50,12 +50,10 @@ namespace sqlpp
static_assert(not ::sqlpp::detail::has_duplicates<Assignments...>::value, "at least one duplicate argument detected in set()");
// check for invalid assignments
using _assignment_set = typename ::sqlpp::detail::make_set_if<is_assignment_t, Assignments...>::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<is_assignment_t, Assignments...>::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<must_not_update_t, typename Assignments::_column_t...>::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<must_not_update_t, typename Assignments::_column_t...>::value, "at least one assignment is prohibited by its column definition in set()");
template<typename Assignment>
void add(Assignment assignment)

View File

@ -28,9 +28,9 @@
#define SQLPP_USING_H
#include <sqlpp11/type_traits.h>
#include <sqlpp11/detail/type_set.h>
#include <sqlpp11/vendor/interpretable_list.h>
#include <sqlpp11/vendor/interpret_tuple.h>
#include <sqlpp11/detail/type_set.h>
namespace sqlpp
{
@ -49,8 +49,7 @@ namespace sqlpp
static_assert(not ::sqlpp::detail::has_duplicates<Table...>::value, "at least one duplicate argument detected in using()");
// check for invalid arguments
using _valid_expressions = typename ::sqlpp::detail::make_set_if<is_table_t, Table...>::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<is_table_t, Table...>::value, "at least one argument is not an table in using()");
template<typename T>

View File

@ -31,7 +31,7 @@
#include <sqlpp11/select_fwd.h>
#include <sqlpp11/vendor/expression.h>
#include <sqlpp11/type_traits.h>
#include <sqlpp11/detail/type_set.h>
#include <sqlpp11/detail/logic.h>
#include <sqlpp11/vendor/interpret_tuple.h>
#include <sqlpp11/vendor/interpretable_list.h>
#include <sqlpp11/parameter_list.h>
@ -48,8 +48,7 @@ namespace sqlpp
using _parameter_tuple_t = std::tuple<Expr...>;
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<is_expression_t, Expr...>::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<is_expression_t, Expr...>::value, "at least one argument is not an expression in where()");
using _parameter_list_t = typename make_parameter_list_t<_parameter_tuple_t>::type;