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

Cleaned up a hack in like()

This commit is contained in:
rbock 2014-01-12 16:26:47 +01:00
parent 7fc5c34190
commit f21860e5c5
2 changed files with 53 additions and 55 deletions

View File

@ -27,21 +27,19 @@
#ifndef SQLPP_LIKE_H #ifndef SQLPP_LIKE_H
#define SQLPP_LIKE_H #define SQLPP_LIKE_H
#include <sstream> #include <sqlpp11/boolean.h>
#include <sqlpp11/type_traits.h> #include <sqlpp11/type_traits.h>
#include <sqlpp11/detail/set.h> #include <sqlpp11/detail/set.h>
namespace sqlpp namespace sqlpp
{ {
// The ValueType should be boolean, this is a hack because boolean is not fully defined when the compiler first gets here... template<typename Operand, typename Pattern>
template<typename ValueType, typename Operand, typename Pattern> struct like_t: public boolean::template operators<like_t<Operand, Pattern>>
struct like_t: public ValueType::_base_value_type::template operators<like_t<ValueType, Operand, Pattern>>
{ {
static_assert(is_text_t<Operand>::value, "Operand for like() has to be a text"); static_assert(is_text_t<Operand>::value, "Operand for like() has to be a text");
static_assert(is_text_t<Pattern>::value, "Pattern for like() has to be a text"); static_assert(is_text_t<Pattern>::value, "Pattern for like() has to be a text");
using _parameter_tuple_t = std::tuple<ValueType, Pattern>;
struct _value_type: public ValueType::_base_value_type // we require fully defined boolean here struct _value_type: public boolean
{ {
using _is_named_expression = std::true_type; using _is_named_expression = std::true_type;
}; };
@ -86,10 +84,10 @@ namespace sqlpp
Pattern _pattern; Pattern _pattern;
}; };
template<typename Context, typename ValueType, typename Operand, typename Pattern> template<typename Context, typename Operand, typename Pattern>
struct interpreter_t<Context, like_t<ValueType, Operand, Pattern>> struct interpreter_t<Context, like_t<Operand, Pattern>>
{ {
using T = like_t<ValueType, Operand, Pattern>; using T = like_t<Operand, Pattern>;
static Context& _(const T& t, Context& context) static Context& _(const T& t, Context& context)
{ {

View File

@ -203,7 +203,7 @@ namespace sqlpp
} }
template<typename T> template<typename T>
like_t<boolean, Base, typename _constraint<T>::type> like(T&& t) const like_t<Base, typename _constraint<T>::type> like(T&& t) const
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used as left hand side operand"); static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used as left hand side operand");
return { *static_cast<const Base*>(this), {std::forward<T>(t)} }; return { *static_cast<const Base*>(this), {std::forward<T>(t)} };