diff --git a/include/sqlpp11/cte.h b/include/sqlpp11/cte.h index d5a93336..54a2d984 100644 --- a/include/sqlpp11/cte.h +++ b/include/sqlpp11/cte.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, Roland Bock + * Copyright (c) 2013-2016, Roland Bock * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -27,16 +27,16 @@ #ifndef SQLPP_CTE_H #define SQLPP_CTE_H -#include -#include -#include -#include -#include -#include #include #include #include #include +#include +#include +#include +#include +#include +#include namespace sqlpp { @@ -133,6 +133,31 @@ namespace sqlpp using type = member_t, column_t>>; }; + template + struct union_cte_impl + { + using type = Check; + }; + + template + struct union_cte_impl + { + using type = Union; + }; + + template + using union_cte_impl_t = typename union_cte_impl::type; + + SQLPP_PORTABLE_STATIC_ASSERT(assert_cte_union_args_are_statements_t, "argument for union() must be a statement"); + template + struct check_cte_union + { + using type = static_combined_check_t< + static_check_t::value...>::value, assert_cte_union_args_are_statements_t>>; + }; + template + using check_cte_union_t = typename check_cte_union::type; + template struct cte_t : public cte_base::type... { @@ -146,21 +171,12 @@ namespace sqlpp using _column_tuple_t = std::tuple>...>; - // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2086629 - // template - // using _check = logic::all_t::value...>; - template - struct _check : logic::all_t::value...> - { - }; - using _result_row_t = result_row_t; template - auto union_distinct(Rhs rhs) const -> - typename std::conditional<_check::value, - cte_t, FieldSpecs...>, - bad_statement>::type + auto union_distinct(Rhs rhs) const + -> union_cte_impl_t, + cte_t, FieldSpecs...>> { static_assert(is_statement_t::value, "argument of union call has to be a statement"); static_assert(has_policy_t::value, "argument of union call has to be a select"); @@ -169,14 +185,13 @@ namespace sqlpp static_assert(std::is_same<_result_row_t, get_result_row_t>::value, "both select statements in a union have to have the same result columns (type and name)"); - return _union_impl(_check{}, rhs); + return _union_impl(check_cte_union_t{}, rhs); } template - auto union_all(Rhs rhs) const -> - typename std::conditional<_check::value, - cte_t, FieldSpecs...>, - bad_statement>::type + auto union_all(Rhs rhs) const + -> union_cte_impl_t, + cte_t, FieldSpecs...>> { static_assert(is_statement_t::value, "argument of union call has to be a statement"); static_assert(has_policy_t::value, "argument of union call has to be a select"); @@ -185,15 +200,15 @@ namespace sqlpp static_assert(std::is_same<_result_row_t, get_result_row_t>::value, "both select statements in a union have to have the same result columns (type and name)"); - return _union_impl(_check{}, rhs); + return _union_impl(check_cte_union_t{}, rhs); } private: - template - auto _union_impl(const std::false_type&, Rhs rhs) const -> bad_statement; + template + auto _union_impl(Check, Rhs rhs) const -> Check; template - auto _union_impl(const std::true_type&, Rhs rhs) const + auto _union_impl(consistent_t, Rhs rhs) const -> cte_t, FieldSpecs...> { return cte_union_t{_statement, rhs};