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

Added several call dispatches to reduce compiler spew in case of errors

This commit is contained in:
rbock 2014-04-10 16:09:54 +02:00
parent ad5584e52d
commit bc5ffc1492
10 changed files with 108 additions and 17 deletions

View File

@ -39,23 +39,23 @@ namespace sqlpp
template<>
struct all_impl<>
{
static constexpr bool value = true;
using type = std::true_type;
};
template<bool... Rest>
struct all_impl<true, Rest...>
{
static constexpr bool value = all_impl<Rest...>::value;
using type = typename all_impl<Rest...>::type;
};
template<bool... Rest>
struct all_impl<false, Rest...>
{
static constexpr bool value = false;
using type = std::false_type;
};
template<template<typename> class Predicate, typename... T>
using all_t = all_impl<Predicate<T>::value...>;
using all_t = typename all_impl<Predicate<T>::value...>::type;
template<bool... b>
struct any_impl;
@ -63,24 +63,27 @@ namespace sqlpp
template<>
struct any_impl<>
{
static constexpr bool value = false;
using type = std::false_type;
};
template<bool... Rest>
struct any_impl<false, Rest...>
{
static constexpr bool value = any_impl<Rest...>::value;
using type = typename all_impl<Rest...>::type;
};
template<bool... Rest>
struct any_impl<true, Rest...>
{
static constexpr bool value = true;
using type = std::true_type;
};
template<template<typename> class Predicate, typename... T>
using any_t = any_impl<Predicate<T>::value...>;
using any_t = typename any_impl<Predicate<T>::value...>::type;
template<typename T>
using identity_t = T;
}
}

View File

@ -145,6 +145,9 @@ namespace sqlpp
using type = typename make_type_set<Rest...>::type::template insert<T>::type;
};
template<typename... T>
using make_type_set_t = typename make_type_set<T...>::type;
template<template<typename> class Predicate, typename... T>
struct make_type_set_if;

View File

@ -99,7 +99,7 @@ namespace sqlpp
template<typename Needle, typename Replacement, typename... Policies>
struct _policies_update_impl
{
#warning: Need to make sure that Needle is in Policies!
static_assert(detail::is_element_of<Needle, make_type_set_t<Policies...>>::value, "policies update for non-policy class detected");
using type = select_t<Db, vendor::policy_update_t<Policies, Needle, Replacement>...>;
};

View File

@ -70,10 +70,23 @@ namespace sqlpp
template<typename Table>
void add_from(Table table)
{
static_assert(is_table_t<Table>::value, "invalid expression argument in add_from()");
#warning: Need to dispatch to actual add method to prevent error messages from being generated
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>>;
_add_from_impl(table, ok()); // dispatch to prevent compile messages after the static_assert
}
private:
template<typename Table>
void _add_from_impl(Table table, const std::true_type&)
{
return static_cast<typename Policies::_statement_t*>(this)->_from._dynamic_tables.emplace_back(table);
}
template<typename Table>
void _add_from_impl(Table table, const std::false_type&);
};
std::tuple<Tables...> _tables;

View File

@ -73,9 +73,21 @@ namespace sqlpp
{
static_assert(_is_dynamic::value, "add_group_by must not be called for static group_by");
static_assert(is_expression_t<Expression>::value, "invalid expression argument in add_group_by()");
#warning: Need to dispatch to actual add method to prevent error messages from being generated
using ok = ::sqlpp::detail::all_t<sqlpp::detail::identity_t, _is_dynamic, is_expression_t<Expression>>;
_add_group_by_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
}
private:
template<typename Expression>
void _add_group_by_impl(Expression expression, const std::true_type&)
{
return static_cast<typename Policies::_statement_t*>(this)->_group_by._dynamic_expressions.emplace_back(expression);
}
template<typename Expression>
void _add_group_by_impl(Expression expression, const std::false_type&);
};
const group_by_t& _group_by() const { return *this; }

View File

@ -71,9 +71,21 @@ namespace sqlpp
{
static_assert(_is_dynamic::value, "add_having must not be called for static having");
static_assert(is_expression_t<Expression>::value, "invalid expression argument in add_having()");
#warning: Need to dispatch to actual add method to prevent error messages from being generated
using ok = ::sqlpp::detail::all_t<sqlpp::detail::identity_t, _is_dynamic, is_expression_t<Expression>>;
_add_having_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
}
private:
template<typename Expression>
void _add_having_impl(Expression expression, const std::true_type&)
{
return static_cast<typename Policies::_statement_t*>(this)->_having._dynamic_expressions.emplace_back(expression);
}
template<typename Expression>
void _add_having_impl(Expression expression, const std::false_type&);
};
_parameter_tuple_t _expressions;

View File

@ -72,9 +72,21 @@ namespace sqlpp
{
static_assert(_is_dynamic::value, "add_order_by must not be called for static order_by");
static_assert(is_sort_order_t<Expression>::value, "invalid expression argument in add_order_by()");
#warning: Need to dispatch to actual add method to prevent error messages from being generated
using ok = ::sqlpp::detail::all_t<sqlpp::detail::identity_t, _is_dynamic, is_sort_order_t<Expression>>;
_add_order_by_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
}
private:
template<typename Expression>
void _add_order_by_impl(Expression expression, const std::true_type&)
{
return static_cast<typename Policies::_statement_t*>(this)->_order_by._dynamic_expressions.emplace_back(expression);
}
template<typename Expression>
void _add_order_by_impl(Expression expression, const std::false_type&);
};
_parameter_tuple_t _expressions;

View File

@ -194,9 +194,21 @@ namespace sqlpp
{
static_assert(_is_dynamic::value, "add_column can only be called for dynamic_column");
static_assert(is_named_expression_t<NamedExpression>::value, "invalid named expression argument in add_column()");
#warning: Need to dispatch to actual add method to prevent error messages from being generated
using ok = ::sqlpp::detail::all_t<sqlpp::detail::identity_t, _is_dynamic, is_named_expression_t<NamedExpression>>;
_add_column_impl(namedExpression, ok()); // dispatch to prevent compile messages after the static_assert
}
private:
template<typename NamedExpression>
void _add_column_impl(NamedExpression namedExpression, const std::true_type&)
{
return static_cast<typename Policies::_statement_t*>(this)->_column_list._dynamic_columns.emplace_back(namedExpression);
}
template<typename NamedExpression>
void _add_column_impl(NamedExpression namedExpression, const std::false_type&);
};

View File

@ -69,9 +69,21 @@ namespace sqlpp
{
static_assert(_is_dynamic::value, "add_flag must not be called for static select flags");
static_assert(is_select_flag_t<Flag>::value, "invalid select flag argument in add_flag()");
#warning: Need to dispatch to actual add method to prevent error messages from being generated
using ok = ::sqlpp::detail::all_t<sqlpp::detail::identity_t, _is_dynamic, is_select_flag_t<Flag>>;
_add_flag_impl(flag, ok()); // dispatch to prevent compile messages after the static_assert
}
private:
template<typename Flag>
void _add_flag_impl(Flag flag, const std::true_type&)
{
return static_cast<typename Policies::_statement_t*>(this)->_flag_list._dynamic_flags.emplace_back(flag);
}
template<typename Flag>
void _add_flag_impl(Flag flag, const std::false_type&);
};
const select_flag_list_t& _flag_list() const { return *this; }

View File

@ -72,9 +72,21 @@ namespace sqlpp
{
static_assert(_is_dynamic::value, "add_where can only be called for dynamic_where");
static_assert(is_expression_t<Expression>::value, "invalid expression argument in add_where()");
#warning: Need to dispatch to actual add method to prevent error messages from being generated
using ok = ::sqlpp::detail::all_t<sqlpp::detail::identity_t, _is_dynamic, is_expression_t<Expression>>;
_add_where_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
}
private:
template<typename Expression>
void _add_where_impl(Expression expression, const std::true_type&)
{
return static_cast<typename Policies::_statement_t*>(this)->_where._dynamic_expressions.emplace_back(expression);
}
template<typename Expression>
void _add_where_impl(Expression expression, const std::false_type&);
};
_parameter_tuple_t _expressions;