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

Cleaned up concat_t and added concat method

This commit is contained in:
rbock 2015-05-05 08:18:39 +02:00
parent 894c5fddfb
commit bcc085f819
3 changed files with 31 additions and 18 deletions

View File

@ -35,17 +35,16 @@
namespace sqlpp
{
// FIXME: Remove First, inherit from text_t
template<typename First, typename... Args>
struct concat_t:
public expression_operators<concat_t<First, Args...>, value_type_of<First>>,
public alias_operators<concat_t<First, Args...>>
{
using _traits = make_traits<value_type_of<First>, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<First, Args...>;
struct text;
template<typename... Args>
struct concat_t:
public expression_operators<concat_t<Args...>, text>,
public alias_operators<concat_t<Args...>>
{
using _traits = make_traits<text, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Args...>;
static_assert(sizeof...(Args) > 0, "concat requires two arguments at least");
static_assert(logic::all_t<is_text_t<First>::value, is_text_t<Args>::value...>::value, "at least one non-text argument detected in concat()");
struct _alias_t
{
static constexpr const char _literal[] = "concat_";
@ -57,8 +56,8 @@ namespace sqlpp
};
};
concat_t(First first, Args... args):
_args(first, args...)
concat_t(Args... args):
_args(args...)
{}
concat_t(const concat_t&) = default;
@ -67,14 +66,14 @@ namespace sqlpp
concat_t& operator=(concat_t&&) = default;
~concat_t() = default;
std::tuple<First, Args...> _args;
std::tuple<Args...> _args;
};
template<typename Context, typename First, typename... Args>
struct serializer_t<Context, concat_t<First, Args...>>
template<typename Context, typename... Args>
struct serializer_t<Context, concat_t<Args...>>
{
using _serialize_check = serialize_check_of<Context, First, Args...>;
using T = concat_t<First, Args...>;
using _serialize_check = serialize_check_of<Context, Args...>;
using T = concat_t<Args...>;
static Context& _(const T& t, Context& context)
{
@ -84,6 +83,16 @@ namespace sqlpp
return context;
}
};
template<typename... Args>
auto concat(Args... args)
-> concat_t<Args...>
{
static_assert(sizeof...(Args) >= 2, "concat requires two arguments at least");
static_assert(logic::all_t<is_text_t<wrap_operand_t<Args>>::value...>::value, "at least one non-text argument detected in concat()");
return {args...};
}
}
#endif

View File

@ -37,6 +37,7 @@
#include <sqlpp11/value_type.h>
#include <sqlpp11/exists.h>
#include <sqlpp11/any.h>
#include <sqlpp11/concat.h>
#include <sqlpp11/some.h>
#include <sqlpp11/count.h>
#include <sqlpp11/min.h>

View File

@ -27,15 +27,18 @@
#ifndef SQLPP_TEXT_H
#define SQLPP_TEXT_H
#include <sqlpp11/assignment.h>
#include <sqlpp11/basic_expression_operators.h>
#include <sqlpp11/type_traits.h>
#include <sqlpp11/exception.h>
#include <sqlpp11/concat.h>
#include <sqlpp11/like.h>
#include <sqlpp11/result_field.h>
namespace sqlpp
{
template<typename... Args>
struct concat_t;
// text value type
struct text
{