mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
Added shift left and shift right operators.
This commit is contained in:
parent
24a0734245
commit
136b533fcf
@ -299,6 +299,20 @@ namespace sqlpp
|
||||
return_type_unary_minus<Expr, Defer>::check::verify();
|
||||
return {*static_cast<const Expr*>(this)};
|
||||
}
|
||||
|
||||
template <typename R>
|
||||
auto operator<<(const R& r) const -> return_type_shift_left_t<Expr, R>
|
||||
{
|
||||
typename return_type_shift_left<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_shift_right_t<Expr, R>
|
||||
{
|
||||
typename return_type_shift_right<Expr, R>::check{};
|
||||
return {*static_cast<const Expr*>(this), wrap_operand_t<R>{r}};
|
||||
}
|
||||
};
|
||||
} // namespace sqlpp
|
||||
|
||||
|
@ -132,5 +132,19 @@ namespace sqlpp
|
||||
using check = consistent_t;
|
||||
using type = bitwise_or_t<wrap_operand_t<L>, integral, wrap_operand_t<R>>;
|
||||
};
|
||||
|
||||
template <typename L, typename R>
|
||||
struct return_type_shift_left<L, R, binary_operand_check_t<L, is_integral_t, R, is_unsigned_integral_t>>
|
||||
{
|
||||
using check = consistent_t;
|
||||
using type = shift_left_t<wrap_operand_t<L>, integral, wrap_operand_t<R>>;
|
||||
};
|
||||
|
||||
template <typename L, typename R>
|
||||
struct return_type_shift_right<L, R, binary_operand_check_t<L, is_integral_t, R, is_unsigned_integral_t>>
|
||||
{
|
||||
using check = consistent_t;
|
||||
using type = shift_right_t<wrap_operand_t<L>, integral, wrap_operand_t<R>>;
|
||||
};
|
||||
} // namespace sqlpp
|
||||
#endif
|
||||
|
@ -113,5 +113,19 @@ namespace sqlpp
|
||||
using check = consistent_t;
|
||||
using type = bitwise_or_t<wrap_operand_t<L>, unsigned_integral, wrap_operand_t<R>>;
|
||||
};
|
||||
|
||||
template <typename L, typename R>
|
||||
struct return_type_shift_left<L, R, binary_operand_check_t<L, is_unsigned_integral_t, R, is_unsigned_integral_t>>
|
||||
{
|
||||
using check = consistent_t;
|
||||
using type = shift_left_t<wrap_operand_t<L>, unsigned_integral, wrap_operand_t<R>>;
|
||||
};
|
||||
|
||||
template <typename L, typename R>
|
||||
struct return_type_shift_right<L, R, binary_operand_check_t<L, is_unsigned_integral_t, R, is_unsigned_integral_t>>
|
||||
{
|
||||
using check = consistent_t;
|
||||
using type = shift_right_t<wrap_operand_t<L>, unsigned_integral, wrap_operand_t<R>>;
|
||||
};
|
||||
} // namespace sqlpp
|
||||
#endif
|
||||
|
@ -157,6 +157,20 @@ namespace sqlpp
|
||||
using _traits = make_traits<ValueType>;
|
||||
static constexpr const char* _name = "|";
|
||||
};
|
||||
|
||||
template <typename ValueType>
|
||||
struct shift_left
|
||||
{
|
||||
using _traits = make_traits<ValueType>;
|
||||
static constexpr const char* _name = "<<";
|
||||
};
|
||||
|
||||
template <typename ValueType>
|
||||
struct shift_right
|
||||
{
|
||||
using _traits = make_traits<ValueType>;
|
||||
static constexpr const char* _name = ">>";
|
||||
};
|
||||
} // namespace op
|
||||
|
||||
template <typename Lhs, typename O, typename Rhs>
|
||||
@ -219,6 +233,12 @@ namespace sqlpp
|
||||
template <typename Lhs, typename ValueType, typename Rhs>
|
||||
using bitwise_or_t = binary_expression_t<Lhs, op::bitwise_or<ValueType>, Rhs>;
|
||||
|
||||
template <typename Lhs, typename ValueType, typename Rhs>
|
||||
using shift_left_t = binary_expression_t<Lhs, op::shift_left<ValueType>, Rhs>;
|
||||
|
||||
template <typename Lhs, typename ValueType, typename Rhs>
|
||||
using shift_right_t = binary_expression_t<Lhs, op::shift_right<ValueType>, Rhs>;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <typename Expr, typename Enable = void>
|
||||
|
@ -49,6 +49,24 @@ namespace sqlpp
|
||||
template <typename L, typename R>
|
||||
using return_type_bitwise_and_t = typename return_type_bitwise_and<L, R>::type;
|
||||
|
||||
template <typename L, typename R, typename Enable = void>
|
||||
struct return_type_shift_left
|
||||
{
|
||||
using check = assert_valid_operands;
|
||||
using type = bad_expression<boolean>;
|
||||
};
|
||||
template <typename L, typename R>
|
||||
using return_type_shift_left_t = typename return_type_shift_left<L, R>::type;
|
||||
|
||||
template <typename L, typename R, typename Enable = void>
|
||||
struct return_type_shift_right
|
||||
{
|
||||
using check = assert_valid_operands;
|
||||
using type = bad_expression<boolean>;
|
||||
};
|
||||
template <typename L, typename R>
|
||||
using return_type_shift_right_t = typename return_type_shift_right<L, R>::type;
|
||||
|
||||
template <typename L, typename R, typename Enable = void>
|
||||
struct return_type_or
|
||||
{
|
||||
|
@ -32,7 +32,13 @@
|
||||
namespace sqlpp
|
||||
{
|
||||
template <typename T>
|
||||
auto value(T t) -> wrap_operand_t<T>
|
||||
struct value_t : public wrap_operand_t<T>, public expression_operators<value_t<T>, value_type_of<wrap_operand_t<T>>>
|
||||
{
|
||||
using _base_t = wrap_operand_t<T>;
|
||||
using _base_t::_base_t;
|
||||
};
|
||||
template <typename T>
|
||||
auto value(T t) -> value_t<T>
|
||||
{
|
||||
static_assert(is_wrapped_value_t<wrap_operand_t<T>>::value,
|
||||
"value() is to be called with non-sql-type like int, or string");
|
||||
|
@ -31,7 +31,8 @@ set(test_serializer_names
|
||||
From
|
||||
In
|
||||
Insert
|
||||
Over
|
||||
Operator
|
||||
Over
|
||||
TableAlias
|
||||
Where
|
||||
ParameterizedVerbatim
|
||||
|
52
tests/core/serialize/Operator.cpp
Normal file
52
tests/core/serialize/Operator.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021, Roland Bock
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "Sample.h"
|
||||
#include "compare.h"
|
||||
#include <sqlpp11/sqlpp11.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
SQLPP_ALIAS_PROVIDER(sample)
|
||||
|
||||
int Operator(int, char* [])
|
||||
{
|
||||
const auto foo = test::TabFoo{};
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
// Plus
|
||||
compare(__LINE__, bar.alpha + 3u, "(tab_bar.alpha+3)");
|
||||
compare(__LINE__, sqlpp::value(3) + foo.psi, "(3+tab_foo.psi)");
|
||||
|
||||
// Shift left
|
||||
compare(__LINE__, sqlpp::value(3) << foo.psi, "(3<<tab_foo.psi)");
|
||||
compare(__LINE__, bar.alpha << 3u, "(tab_bar.alpha<<3)");
|
||||
|
||||
// Shift right
|
||||
compare(__LINE__, sqlpp::value(3) >> foo.psi, "(3>>tab_foo.psi)");
|
||||
compare(__LINE__, bar.alpha >> 3u, "(tab_bar.alpha>>3)");
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user