mirror of
https://github.com/rbock/sqlpp11.git
synced 2026-01-08 06:00:40 -06:00
Moved operator and parameter templates out of value classes, added member template
These templates are nicer when used.
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#ifndef SQLPP_DETAIL_BASIC_EXPRESSION_OPERATORS_H
|
||||
#define SQLPP_DETAIL_BASIC_EXPRESSION_OPERATORS_H
|
||||
|
||||
#include <sqlpp11/value_type_fwd.h>
|
||||
#include <sqlpp11/alias.h>
|
||||
#include <sqlpp11/sort_order.h>
|
||||
#include <sqlpp11/expression_fwd.h>
|
||||
@@ -38,7 +39,7 @@
|
||||
namespace sqlpp
|
||||
{
|
||||
// basic operators
|
||||
template<typename Base, template<typename> class IsCorrectValueType>
|
||||
template<typename Expr, typename ValueType>
|
||||
struct basic_expression_operators
|
||||
{
|
||||
template<typename T>
|
||||
@@ -47,107 +48,107 @@ namespace sqlpp
|
||||
static constexpr bool value =
|
||||
(is_expression_t<T>::value // expressions are OK
|
||||
or is_multi_expression_t<T>::value) // multi-expressions like ANY are OK for comparisons, too
|
||||
and IsCorrectValueType<T>::value // the correct value type is required, of course
|
||||
and ValueType::template _is_valid_operand<T>::value // the correct value type is required, of course
|
||||
;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
equal_to_t<Base, wrap_operand_t<T>> operator==(T t) const
|
||||
equal_to_t<Expr, wrap_operand_t<T>> operator==(T t) const
|
||||
{
|
||||
using rhs = wrap_operand_t<T>;
|
||||
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
|
||||
|
||||
return { *static_cast<const Base*>(this), {rhs{t}} };
|
||||
return { *static_cast<const Expr*>(this), {rhs{t}} };
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
not_equal_to_t<Base, wrap_operand_t<T>> operator!=(T t) const
|
||||
not_equal_to_t<Expr, wrap_operand_t<T>> operator!=(T t) const
|
||||
{
|
||||
using rhs = wrap_operand_t<T>;
|
||||
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
|
||||
|
||||
return { *static_cast<const Base*>(this), {rhs{t}} };
|
||||
return { *static_cast<const Expr*>(this), {rhs{t}} };
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
less_than_t<Base, wrap_operand_t<T>> operator<(T t) const
|
||||
less_than_t<Expr, wrap_operand_t<T>> operator<(T t) const
|
||||
{
|
||||
using rhs = wrap_operand_t<T>;
|
||||
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
|
||||
|
||||
return { *static_cast<const Base*>(this), rhs{t} };
|
||||
return { *static_cast<const Expr*>(this), rhs{t} };
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
less_equal_t<Base, wrap_operand_t<T>> operator<=(T t) const
|
||||
less_equal_t<Expr, wrap_operand_t<T>> operator<=(T t) const
|
||||
{
|
||||
using rhs = wrap_operand_t<T>;
|
||||
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
|
||||
|
||||
return { *static_cast<const Base*>(this), rhs{t} };
|
||||
return { *static_cast<const Expr*>(this), rhs{t} };
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
greater_than_t<Base, wrap_operand_t<T>> operator>(T t) const
|
||||
greater_than_t<Expr, wrap_operand_t<T>> operator>(T t) const
|
||||
{
|
||||
using rhs = wrap_operand_t<T>;
|
||||
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
|
||||
|
||||
return { *static_cast<const Base*>(this), rhs{t} };
|
||||
return { *static_cast<const Expr*>(this), rhs{t} };
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
greater_equal_t<Base, wrap_operand_t<T>> operator>=(T t) const
|
||||
greater_equal_t<Expr, wrap_operand_t<T>> operator>=(T t) const
|
||||
{
|
||||
using rhs = wrap_operand_t<T>;
|
||||
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
|
||||
|
||||
return { *static_cast<const Base*>(this), rhs{t} };
|
||||
return { *static_cast<const Expr*>(this), rhs{t} };
|
||||
}
|
||||
|
||||
is_null_t<true, Base> is_null() const
|
||||
is_null_t<true, Expr> is_null() const
|
||||
{
|
||||
return { *static_cast<const Base*>(this) };
|
||||
return { *static_cast<const Expr*>(this) };
|
||||
}
|
||||
|
||||
is_null_t<false, Base> is_not_null() const
|
||||
is_null_t<false, Expr> is_not_null() const
|
||||
{
|
||||
return { *static_cast<const Base*>(this) };
|
||||
return { *static_cast<const Expr*>(this) };
|
||||
}
|
||||
|
||||
sort_order_t<Base, sort_type::asc> asc() const
|
||||
sort_order_t<Expr, sort_type::asc> asc() const
|
||||
{
|
||||
return { *static_cast<const Base*>(this) };
|
||||
return { *static_cast<const Expr*>(this) };
|
||||
}
|
||||
|
||||
sort_order_t<Base, sort_type::desc> desc() const
|
||||
sort_order_t<Expr, sort_type::desc> desc() const
|
||||
{
|
||||
return { *static_cast<const Base*>(this) };
|
||||
return { *static_cast<const Expr*>(this) };
|
||||
}
|
||||
|
||||
// Hint: use value_list wrapper for containers...
|
||||
template<typename... T>
|
||||
in_t<true, Base, wrap_operand_t<T>...> in(T... t) const
|
||||
in_t<true, Expr, wrap_operand_t<T>...> in(T... t) const
|
||||
{
|
||||
static_assert(detail::all_t<_is_valid_comparison_operand<wrap_operand_t<T>>::value...>::value, "at least one operand of in() is not valid");
|
||||
return { *static_cast<const Base*>(this), wrap_operand_t<T>{t}... };
|
||||
return { *static_cast<const Expr*>(this), wrap_operand_t<T>{t}... };
|
||||
}
|
||||
|
||||
template<typename... T>
|
||||
in_t<false, Base, wrap_operand_t<T>...> not_in(T... t) const
|
||||
in_t<false, Expr, wrap_operand_t<T>...> not_in(T... t) const
|
||||
{
|
||||
static_assert(detail::all_t<_is_valid_comparison_operand<wrap_operand_t<T>>::value...>::value, "at least one operand of in() is not valid");
|
||||
return { *static_cast<const Base*>(this), wrap_operand_t<T>{t}... };
|
||||
return { *static_cast<const Expr*>(this), wrap_operand_t<T>{t}... };
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Base>
|
||||
template<typename Expr>
|
||||
struct alias_operators
|
||||
{
|
||||
template<typename alias_provider>
|
||||
expression_alias_t<Base, alias_provider> as(const alias_provider&) const
|
||||
expression_alias_t<Expr, alias_provider> as(const alias_provider&) const
|
||||
{
|
||||
return { *static_cast<const Base*>(this) };
|
||||
return { *static_cast<const Expr*>(this) };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user