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

More re-arrangements and preventing self-compare in in() again

This commit is contained in:
rbock 2016-04-09 10:55:46 +02:00
parent 6c1b190dcc
commit 0fb188c67d
5 changed files with 56 additions and 58 deletions

View File

@ -41,25 +41,26 @@
namespace sqlpp
{
SQLPP_PORTABLE_STATIC_ASSERT(assert_comparison_valid_rhs_operand_t, "invalid rhs operand in comparison");
SQLPP_PORTABLE_STATIC_ASSERT(assert_comparison_rhs_is_expression_t, "rhs operand in comparison is not an expression");
SQLPP_PORTABLE_STATIC_ASSERT(assert_comparison_rhs_is_valid_operand_t, "invalid rhs operand in comparison");
SQLPP_PORTABLE_STATIC_ASSERT(assert_comparison_lhs_rhs_differ_t, "identical lhs and rhs operands in comparison");
template <typename LhsType, typename RhsType>
using check_rhs_comparison_operand_t = static_combined_check_t<
static_check_t<(is_expression_t<sqlpp::wrap_operand_t<RhsType>>::value // expressions are OK
or
is_multi_expression_t<sqlpp::wrap_operand_t<RhsType>>::value) // multi-expressions like ANY are
// OK for comparisons, too
and
value_type_of<LhsType>::template _is_valid_operand<
sqlpp::wrap_operand_t<RhsType>>::value, // the correct value type is required, of course
assert_comparison_valid_rhs_operand_t>,
using check_comparison_t = static_combined_check_t<
static_check_t<logic::any_t<is_expression_t<sqlpp::wrap_operand_t<RhsType>>::value,
is_multi_expression_t<sqlpp::wrap_operand_t<RhsType>>::value>::value,
assert_comparison_rhs_is_expression_t>,
static_check_t<value_type_of<LhsType>::template _is_valid_operand<sqlpp::wrap_operand_t<RhsType>>::value,
assert_comparison_rhs_is_valid_operand_t>,
static_check_t<not std::is_same<LhsType, RhsType>::value, assert_comparison_lhs_rhs_differ_t>>;
template <typename LhsType, typename... RhsType>
using check_rhs_in_operands_t = static_combined_check_t<
using check_in_t = static_combined_check_t<
static_check_t<logic::all_t<is_expression_t<sqlpp::wrap_operand_t<RhsType>>::value...>::value,
assert_comparison_valid_rhs_operand_t>,
assert_comparison_rhs_is_expression_t>,
static_check_t<logic::all_t<value_type_of<LhsType>::template _is_valid_operand<
sqlpp::wrap_operand_t<RhsType>>::value...>::value,
assert_comparison_rhs_is_valid_operand_t>,
static_check_t<logic::none_t<std::is_same<LhsType, RhsType>::value...>::value,
assert_comparison_lhs_rhs_differ_t>>;
@ -104,10 +105,8 @@ namespace sqlpp
template <template <typename Lhs, typename Rhs> class NewExpr, typename T>
struct _new_binary_expression
{
using type = new_binary_expression_t<check_rhs_comparison_operand_t<Expr, wrap_operand_t<T>>,
NewExpr,
Expr,
wrap_operand_t<T>>;
using type =
new_binary_expression_t<check_comparison_t<Expr, wrap_operand_t<T>>, NewExpr, Expr, wrap_operand_t<T>>;
};
template <template <typename Lhs, typename Rhs> class NewExpr, typename T>
using _new_binary_expression_t = typename _new_binary_expression<NewExpr, T>::type;
@ -115,7 +114,7 @@ namespace sqlpp
// workaround for msvs bug
// template <template <typename Lhs, typename... Rhs> class NewExpr, typename... T>
// using _new_nary_expression_t =
// new_nary_expression_t<logic::all_t<check_rhs_comparison_operand_t<
// new_nary_expression_t<logic::all_t<check_comparison_t<
// wrap_operand_t<T>>::value...>,
// NewExpr,
// Expr,
@ -123,18 +122,17 @@ namespace sqlpp
template <template <typename Lhs, typename... Rhs> class NewExpr, typename... T>
struct _new_nary_expression
{
using type =
new_nary_expression_t<logic::all_t<check_rhs_comparison_operand_t<Expr, wrap_operand_t<T>>::value...>,
NewExpr,
Expr,
wrap_operand_t<T>...>;
using type = new_nary_expression_t<logic::all_t<check_comparison_t<Expr, wrap_operand_t<T>>::value...>,
NewExpr,
Expr,
wrap_operand_t<T>...>;
};
template <typename T>
_new_binary_expression_t<equal_to_t, T> operator==(T t) const
{
using rhs = wrap_operand_t<T>;
check_rhs_comparison_operand_t<Expr, rhs>::_();
check_comparison_t<Expr, rhs>::_();
return {*static_cast<const Expr*>(this), rhs{t}};
}
@ -143,7 +141,7 @@ namespace sqlpp
_new_binary_expression_t<not_equal_to_t, T> operator!=(T t) const
{
using rhs = wrap_operand_t<T>;
check_rhs_comparison_operand_t<Expr, rhs>::_();
check_comparison_t<Expr, rhs>::_();
return {*static_cast<const Expr*>(this), rhs{t}};
}
@ -152,7 +150,7 @@ namespace sqlpp
_new_binary_expression_t<less_than_t, T> operator<(T t) const
{
using rhs = wrap_operand_t<T>;
check_rhs_comparison_operand_t<Expr, rhs>::_();
check_comparison_t<Expr, rhs>::_();
return {*static_cast<const Expr*>(this), rhs{t}};
}
@ -161,7 +159,7 @@ namespace sqlpp
_new_binary_expression_t<less_equal_t, T> operator<=(T t) const
{
using rhs = wrap_operand_t<T>;
check_rhs_comparison_operand_t<Expr, rhs>::_();
check_comparison_t<Expr, rhs>::_();
return {*static_cast<const Expr*>(this), rhs{t}};
}
@ -170,7 +168,7 @@ namespace sqlpp
_new_binary_expression_t<greater_than_t, T> operator>(T t) const
{
using rhs = wrap_operand_t<T>;
check_rhs_comparison_operand_t<Expr, rhs>::_();
check_comparison_t<Expr, rhs>::_();
return {*static_cast<const Expr*>(this), rhs{t}};
}
@ -179,7 +177,7 @@ namespace sqlpp
_new_binary_expression_t<greater_equal_t, T> operator>=(T t) const
{
using rhs = wrap_operand_t<T>;
check_rhs_comparison_operand_t<Expr, rhs>::_();
check_comparison_t<Expr, rhs>::_();
return {*static_cast<const Expr*>(this), rhs{t}};
}
@ -215,7 +213,7 @@ namespace sqlpp
template <typename... T>
typename _new_nary_expression<in_t, T...>::type in(T... t) const
{
check_rhs_in_operands_t<Expr, T...>::_();
check_in_t<Expr, T...>::_();
return {*static_cast<const Expr*>(this), typename wrap_operand<T>::type{t}...};
}
@ -229,7 +227,7 @@ namespace sqlpp
template <typename... T>
typename _new_nary_expression<not_in_t, T...>::type not_in(T... t) const
{
check_rhs_in_operands_t<Expr, T...>::_();
check_in_t<Expr, T...>::_();
return {*static_cast<const Expr*>(this), typename wrap_operand<T>::type{t}...};
}

View File

@ -46,7 +46,7 @@ namespace
template <typename Assert, typename Operand>
void static_check_comparison(const Operand& operand)
{
using CheckResult = sqlpp::check_rhs_comparison_operand_t<decltype(t.someDayPoint), Operand>;
using CheckResult = sqlpp::check_comparison_t<decltype(t.someDayPoint), Operand>;
using ExpectedCheckResult = std::is_same<CheckResult, Assert>;
static_assert(ExpectedCheckResult::value, "Unexpected check result");
print_type_on_error<CheckResult>(ExpectedCheckResult{});
@ -73,14 +73,14 @@ namespace
void disallowed_comparands()
{
static_check_comparison<sqlpp::assert_comparison_valid_rhs_operand_t>(17);
static_check_comparison<sqlpp::assert_comparison_valid_rhs_operand_t>('a');
static_check_comparison<sqlpp::assert_comparison_valid_rhs_operand_t>(std::string("a"));
static_check_comparison<sqlpp::assert_comparison_valid_rhs_operand_t>(t);
static_check_comparison<sqlpp::assert_comparison_valid_rhs_operand_t>(t.someBool);
static_check_comparison<sqlpp::assert_comparison_valid_rhs_operand_t>(t.someFloat);
static_check_comparison<sqlpp::assert_comparison_valid_rhs_operand_t>(t.someInt);
static_check_comparison<sqlpp::assert_comparison_valid_rhs_operand_t>(t.someString);
static_check_comparison<sqlpp::assert_comparison_rhs_is_valid_operand_t>(17);
static_check_comparison<sqlpp::assert_comparison_rhs_is_valid_operand_t>('a');
static_check_comparison<sqlpp::assert_comparison_rhs_is_valid_operand_t>(std::string("a"));
static_check_comparison<sqlpp::assert_comparison_rhs_is_expression_t>(t);
static_check_comparison<sqlpp::assert_comparison_rhs_is_valid_operand_t>(t.someBool);
static_check_comparison<sqlpp::assert_comparison_rhs_is_valid_operand_t>(t.someFloat);
static_check_comparison<sqlpp::assert_comparison_rhs_is_valid_operand_t>(t.someInt);
static_check_comparison<sqlpp::assert_comparison_rhs_is_valid_operand_t>(t.someString);
}
}

View File

@ -46,7 +46,7 @@ namespace
template <typename Assert, typename Operand>
void static_check_comparison(const Operand& operand)
{
using CheckResult = sqlpp::check_rhs_comparison_operand_t<decltype(t.someTimePoint), Operand>;
using CheckResult = sqlpp::check_comparison_t<decltype(t.someTimePoint), Operand>;
using ExpectedCheckResult = std::is_same<CheckResult, Assert>;
static_assert(ExpectedCheckResult::value, "Unexpected check result");
print_type_on_error<CheckResult>(ExpectedCheckResult{});
@ -73,14 +73,14 @@ namespace
void disallowed_comparands()
{
static_check_comparison<sqlpp::assert_comparison_valid_rhs_operand_t>(17);
static_check_comparison<sqlpp::assert_comparison_valid_rhs_operand_t>('a');
static_check_comparison<sqlpp::assert_comparison_valid_rhs_operand_t>(std::string("a"));
static_check_comparison<sqlpp::assert_comparison_valid_rhs_operand_t>(t);
static_check_comparison<sqlpp::assert_comparison_valid_rhs_operand_t>(t.someBool);
static_check_comparison<sqlpp::assert_comparison_valid_rhs_operand_t>(t.someFloat);
static_check_comparison<sqlpp::assert_comparison_valid_rhs_operand_t>(t.someInt);
static_check_comparison<sqlpp::assert_comparison_valid_rhs_operand_t>(t.someString);
static_check_comparison<sqlpp::assert_comparison_rhs_is_valid_operand_t>(17);
static_check_comparison<sqlpp::assert_comparison_rhs_is_valid_operand_t>('a');
static_check_comparison<sqlpp::assert_comparison_rhs_is_valid_operand_t>(std::string("a"));
static_check_comparison<sqlpp::assert_comparison_rhs_is_expression_t>(t);
static_check_comparison<sqlpp::assert_comparison_rhs_is_valid_operand_t>(t.someBool);
static_check_comparison<sqlpp::assert_comparison_rhs_is_valid_operand_t>(t.someFloat);
static_check_comparison<sqlpp::assert_comparison_rhs_is_valid_operand_t>(t.someInt);
static_check_comparison<sqlpp::assert_comparison_rhs_is_valid_operand_t>(t.someString);
}
}

View File

@ -46,7 +46,7 @@ namespace
template <typename Assert, typename Operand>
void static_check_self_compare(const Operand& operand)
{
using CheckResult = sqlpp::check_rhs_comparison_operand_t<Operand, Operand>;
using CheckResult = sqlpp::check_comparison_t<Operand, Operand>;
using ExpectedCheckResult = std::is_same<CheckResult, Assert>;
static_assert(ExpectedCheckResult::value, "Unexpected check result");
print_type_on_error<CheckResult>(ExpectedCheckResult{});

View File

@ -46,7 +46,7 @@ namespace
template <typename Assert, typename Operand>
void static_check_comparison(const Operand& operand)
{
using CheckResult = sqlpp::check_rhs_comparison_operand_t<decltype(t.someString), Operand>;
using CheckResult = sqlpp::check_comparison_t<decltype(t.someString), Operand>;
using ExpectedCheckResult = std::is_same<CheckResult, Assert>;
static_assert(ExpectedCheckResult::value, "Unexpected check result");
print_type_on_error<CheckResult>(ExpectedCheckResult{});
@ -73,14 +73,14 @@ namespace
void disallowed_comparands()
{
static_check_comparison<sqlpp::assert_comparison_valid_rhs_operand_t>(17);
static_check_comparison<sqlpp::assert_comparison_valid_rhs_operand_t>(17.4);
static_check_comparison<sqlpp::assert_comparison_valid_rhs_operand_t>(t);
static_check_comparison<sqlpp::assert_comparison_valid_rhs_operand_t>(t.someBool);
static_check_comparison<sqlpp::assert_comparison_valid_rhs_operand_t>(t.someFloat);
static_check_comparison<sqlpp::assert_comparison_valid_rhs_operand_t>(t.someInt);
static_check_comparison<sqlpp::assert_comparison_valid_rhs_operand_t>(t.someDayPoint);
static_check_comparison<sqlpp::assert_comparison_valid_rhs_operand_t>(t.someTimePoint);
static_check_comparison<sqlpp::assert_comparison_rhs_is_valid_operand_t>(17);
static_check_comparison<sqlpp::assert_comparison_rhs_is_valid_operand_t>(17.4);
static_check_comparison<sqlpp::assert_comparison_rhs_is_expression_t>(t);
static_check_comparison<sqlpp::assert_comparison_rhs_is_valid_operand_t>(t.someBool);
static_check_comparison<sqlpp::assert_comparison_rhs_is_valid_operand_t>(t.someFloat);
static_check_comparison<sqlpp::assert_comparison_rhs_is_valid_operand_t>(t.someInt);
static_check_comparison<sqlpp::assert_comparison_rhs_is_valid_operand_t>(t.someDayPoint);
static_check_comparison<sqlpp::assert_comparison_rhs_is_valid_operand_t>(t.someTimePoint);
}
template <typename Expected, typename Expression>