0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 04:47:18 +08:00

Started to migrate integral operators.

Looks good...
This commit is contained in:
rbock 2015-11-08 20:07:22 +01:00
parent 29bf1529e4
commit 8ae9966f5d
4 changed files with 148 additions and 49 deletions

View File

@ -239,6 +239,48 @@ namespace sqlpp
return_type_or<Expr, R>::check::_();
return {*static_cast<const Expr*>(this), wrap_operand_t<R>{r}};
}
template <typename R>
auto operator+(const R& r) const -> return_type_plus_t<Expr, R>
{
return_type_plus<Expr, R>::check::_();
return {*static_cast<const Expr*>(this), wrap_operand_t<R>{r}};
}
template <typename R>
auto operator-(const R& r) const -> return_type_minus_t<Expr, R>
{
return_type_minus<Expr, R>::check::_();
return {*static_cast<const Expr*>(this), wrap_operand_t<R>{r}};
}
template <typename R>
auto operator*(const R& r) const -> return_type_multiplies_t<Expr, R>
{
return_type_multiplies<Expr, R>::check::_();
return {*static_cast<const Expr*>(this), wrap_operand_t<R>{r}};
}
template <typename R>
auto operator/(const R& r) const -> return_type_divides_t<Expr, R>
{
return_type_divides<Expr, R>::check::_();
return {*static_cast<const Expr*>(this), wrap_operand_t<R>{r}};
}
template <typename Defer = void>
auto operator+() const -> return_type_unary_plus_t<Expr, Defer>
{
return_type_unary_plus<Expr, Defer>::check::_();
return {*static_cast<const Expr*>(this)};
}
template <typename Defer = void>
auto operator-() const -> return_type_unary_minus_t<Expr, Defer>
{
return_type_unary_minus<Expr, Defer>::check::_();
return {*static_cast<const Expr*>(this)};
}
};
}

View File

@ -27,7 +27,6 @@
#ifndef SQLPP_BOOLEAN_EXPRESSION_OPERATORS_H
#define SQLPP_BOOLEAN_EXPRESSION_OPERATORS_H
//#include <sqlpp11/operators.h>
#include <sqlpp11/expression_return_types.h>
#include <sqlpp11/operand_check.h>
#include <sqlpp11/expression_operators.h>

View File

@ -27,6 +27,8 @@
#ifndef SQLPP_INTEGRAL_EXPRESSION_OPERATORS_H
#define SQLPP_INTEGRAL_EXPRESSION_OPERATORS_H
#include <sqlpp11/expression_return_types.h>
#include <sqlpp11/operand_check.h>
#include <sqlpp11/expression_operators.h>
#include <sqlpp11/basic_expression_operators.h>
#include <sqlpp11/value_type.h>
@ -35,84 +37,80 @@
namespace sqlpp
{
template <typename Base>
struct expression_operators<Base, integral> : public basic_expression_operators<Base, integral>
template <typename Expression>
struct expression_operators<Expression, integral> : public basic_expression_operators<Expression, integral>
{
template <typename T>
using _is_valid_operand = is_valid_operand<integral, T>;
template <typename T>
plus_t<Base, value_type_t<T>, wrap_operand_t<T>> operator+(T t) const
modulus_t<Expression, wrap_operand_t<T>> operator%(T t) const
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
return {*static_cast<const Base*>(this), {t}};
return {*static_cast<const Expression*>(this), {t}};
}
template <typename T>
minus_t<Base, value_type_t<T>, wrap_operand_t<T>> operator-(T t) const
bitwise_and_t<Expression, value_type_t<T>, wrap_operand_t<T>> operator&(T t) const
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
return {*static_cast<const Base*>(this), {t}};
return {*static_cast<const Expression*>(this), {t}};
}
template <typename T>
multiplies_t<Base, value_type_t<T>, wrap_operand_t<T>> operator*(T t) const
bitwise_or_t<Expression, value_type_t<T>, wrap_operand_t<T>> operator|(T t) const
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
return {*static_cast<const Base*>(this), {t}};
return {*static_cast<const Expression*>(this), {t}};
}
};
template <typename T>
divides_t<Base, wrap_operand_t<T>> operator/(T t) const
template <typename L, typename R>
struct return_type_plus<L, R, binary_operand_check_t<L, is_integral_t, R, is_numeric_t>>
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
using check = consistent_t;
using type = plus_t<wrap_operand_t<L>, value_type_of<wrap_operand_t<R>>, wrap_operand_t<R>>;
};
return {*static_cast<const Base*>(this), {t}};
}
template <typename T>
modulus_t<Base, wrap_operand_t<T>> operator%(T t) const
template <typename L, typename R>
struct return_type_minus<L, R, binary_operand_check_t<L, is_integral_t, R, is_numeric_t>>
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
using check = consistent_t;
using type = minus_t<wrap_operand_t<L>, value_type_of<wrap_operand_t<R>>, wrap_operand_t<R>>;
};
return {*static_cast<const Base*>(this), {t}};
}
unary_plus_t<integral, Base> operator+() const
template <typename L, typename R>
struct return_type_multiplies<L, R, binary_operand_check_t<L, is_integral_t, R, is_numeric_t>>
{
return {*static_cast<const Base*>(this)};
}
using check = consistent_t;
using type = multiplies_t<wrap_operand_t<L>, value_type_of<wrap_operand_t<R>>, wrap_operand_t<R>>;
};
unary_minus_t<integral, Base> operator-() const
template <typename L, typename R>
struct return_type_divides<L, R, binary_operand_check_t<L, is_integral_t, R, is_numeric_t>>
{
return {*static_cast<const Base*>(this)};
}
using check = consistent_t;
using type = divides_t<wrap_operand_t<L>, wrap_operand_t<R>>;
};
template <typename T>
bitwise_and_t<Base, value_type_t<T>, wrap_operand_t<T>> operator&(T t) const
template <typename T, typename Defer>
struct return_type_unary_plus<T, Defer, unary_operand_check_t<T, is_integral_t>>
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
using check = consistent_t;
using type = unary_plus_t<integral, wrap_operand_t<T>>;
};
return {*static_cast<const Base*>(this), {t}};
}
template <typename T>
bitwise_or_t<Base, value_type_t<T>, wrap_operand_t<T>> operator|(T t) const
template <typename T, typename Defer>
struct return_type_unary_minus<T, Defer, unary_operand_check_t<T, is_integral_t>>
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
return {*static_cast<const Base*>(this), {t}};
}
using check = consistent_t;
using type = unary_minus_t<integral, wrap_operand_t<T>>;
};
}
#endif

View File

@ -60,6 +60,66 @@ namespace sqlpp
template <typename T, typename Defer>
using return_type_not_t = typename return_type_not<T, Defer>::type;
template <typename L, typename R, typename Enable = void>
struct return_type_plus
{
using check = assert_valid_operands;
using type = bad_expression<boolean>;
};
template <typename L, typename R>
using return_type_plus_t = typename return_type_plus<L, R>::type;
template <typename L, typename R, typename Enable = void>
struct return_type_minus
{
using check = assert_valid_operands;
using type = bad_expression<boolean>;
};
template <typename L, typename R>
using return_type_minus_t = typename return_type_minus<L, R>::type;
template <typename L, typename R, typename Enable = void>
struct return_type_multiplies
{
using check = assert_valid_operands;
using type = bad_expression<boolean>;
};
template <typename L, typename R>
using return_type_multiplies_t = typename return_type_multiplies<L, R>::type;
template <typename L, typename R, typename Enable = void>
struct return_type_divides
{
using check = assert_valid_operands;
using type = bad_expression<boolean>;
};
template <typename L, typename R>
using return_type_divides_t = typename return_type_divides<L, R>::type;
template <typename T, typename Defer, typename Enable = void>
struct return_type_unary_plus
{
using check = assert_valid_operands;
using type = bad_expression<boolean>;
};
template <typename T, typename Defer>
using return_type_unary_plus_t = typename return_type_unary_plus<T, Defer>::type;
template <typename T, typename Defer, typename Enable = void>
struct return_type_unary_minus
{
using check = assert_valid_operands;
using type = bad_expression<boolean>;
};
template <typename T, typename Defer>
using return_type_unary_minus_t = typename return_type_unary_minus<T, Defer>::type;
}
#endif