From bcc085f819d6222665307545553e73a4df3ece92 Mon Sep 17 00:00:00 2001 From: rbock Date: Tue, 5 May 2015 08:18:39 +0200 Subject: [PATCH] Cleaned up concat_t and added concat method --- include/sqlpp11/concat.h | 43 ++++++++++++++++++++++--------------- include/sqlpp11/functions.h | 1 + include/sqlpp11/text.h | 5 ++++- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/include/sqlpp11/concat.h b/include/sqlpp11/concat.h index bc0ac76b..d93cdf52 100644 --- a/include/sqlpp11/concat.h +++ b/include/sqlpp11/concat.h @@ -35,17 +35,16 @@ namespace sqlpp { - // FIXME: Remove First, inherit from text_t - template - struct concat_t: - public expression_operators, value_type_of>, - public alias_operators> - { - using _traits = make_traits, tag::is_expression, tag::is_selectable>; - using _nodes = detail::type_vector; + struct text; + + template + struct concat_t: + public expression_operators, text>, + public alias_operators> + { + using _traits = make_traits; + using _nodes = detail::type_vector; - static_assert(sizeof...(Args) > 0, "concat requires two arguments at least"); - static_assert(logic::all_t::value, is_text_t::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 _args; + std::tuple _args; }; - template - struct serializer_t> + template + struct serializer_t> { - using _serialize_check = serialize_check_of; - using T = concat_t; + using _serialize_check = serialize_check_of; + using T = concat_t; static Context& _(const T& t, Context& context) { @@ -84,6 +83,16 @@ namespace sqlpp return context; } }; + + template + auto concat(Args... args) + -> concat_t + { + static_assert(sizeof...(Args) >= 2, "concat requires two arguments at least"); + static_assert(logic::all_t>::value...>::value, "at least one non-text argument detected in concat()"); + + return {args...}; + } } #endif diff --git a/include/sqlpp11/functions.h b/include/sqlpp11/functions.h index 46776612..bc935e51 100644 --- a/include/sqlpp11/functions.h +++ b/include/sqlpp11/functions.h @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include diff --git a/include/sqlpp11/text.h b/include/sqlpp11/text.h index 6bc388b1..adb5f6ca 100644 --- a/include/sqlpp11/text.h +++ b/include/sqlpp11/text.h @@ -27,15 +27,18 @@ #ifndef SQLPP_TEXT_H #define SQLPP_TEXT_H +#include #include #include #include -#include #include #include namespace sqlpp { + template + struct concat_t; + // text value type struct text {