diff --git a/include/sqlpp11/detail/arg_selector.h b/include/sqlpp11/detail/pick_arg.h similarity index 65% rename from include/sqlpp11/detail/arg_selector.h rename to include/sqlpp11/detail/pick_arg.h index e2922920..ca9f5296 100644 --- a/include/sqlpp11/detail/arg_selector.h +++ b/include/sqlpp11/detail/pick_arg.h @@ -24,23 +24,32 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SQLPP_DETAIL_ARG_SELECTOR_H -#define SQLPP_DETAIL_ARG_SELECTOR_H +#ifndef SQLPP_DETAIL_PICK_ARG_H +#define SQLPP_DETAIL_PICK_ARG_H + +#include namespace sqlpp { namespace detail { - template - struct arg_selector + template + Target pick_arg_impl(Statement statement, Term term, const std::true_type&) { - static Target _(Target, Target t) { return t; } + return term; + }; - template - static Target _(X, Target t) { return t; } + template + Target pick_arg_impl(Statement statement, Term term, const std::false_type&) + { + return static_cast(statement); + }; - template - static Target _(Target t, X) { return t; } + // Returns a statement's term either by picking the term from the statement or using the new term + template + Target pick_arg(Statement statement, Term term) + { + return pick_arg_impl(statement, term, std::is_same()); }; } } diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 8d7033a5..8b12a784 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -47,8 +47,9 @@ #include #include -#include +//#include #include +#include namespace sqlpp { @@ -94,20 +95,20 @@ namespace sqlpp _all_provided_tables // Hint: extra_tables are not used here because they are just a helper for dynamic .add_*() >; - using _result_provider = detail::get_last_if; + using _result_type_provider = detail::get_last_if; // A select can be used as a pseudo table if // - at least one column is selected // - the select is complete (leaks no tables) using _can_be_used_as_table = typename std::conditional< - is_select_column_list_t<_result_provider>::value and _required_tables::size::value == 0, + is_select_column_list_t<_result_type_provider>::value and _required_tables::size::value == 0, std::true_type, std::false_type >::type; using _value_type = typename std::conditional< detail::none_t::value...>::value, - value_type_of<_result_provider>, + value_type_of<_result_type_provider>, no_value_t // if a required statement part is missing (columns in a select), then the statement cannot be used as a value >::type; @@ -124,27 +125,6 @@ namespace sqlpp }; } - namespace detail - { - template - Target pick_arg_impl(Statement statement, Term term, const std::true_type&) - { - return term; - }; - - template - Target pick_arg_impl(Statement statement, Term term, const std::false_type&) - { - return static_cast(statement); - }; - - template - Target pick_arg(Statement statement, Term term) - { - return pick_arg_impl(statement, term, std::is_same()); - }; - } - // SELECT template; using _traits = make_traits, ::sqlpp::tag::select>; - using _recursive_traits = typename _policies_t::_recursive_traits; using _database_t = Db; using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; -#warning replace _column_list_t by a more generic name - using _column_list_t = typename _policies_t::_result_provider; + using _result_type_provider = typename _policies_t::_result_type_provider; using _parameter_tuple_t = std::tuple; using _parameter_list_t = typename make_parameter_list_t::type; template - using _result_row_t = typename _column_list_t::template _result_row_t; - using _dynamic_names_t = typename _column_list_t::_dynamic_names_t; + using _result_row_t = typename _result_type_provider::template _result_row_t; + using _dynamic_names_t = typename _result_type_provider::_dynamic_names_t; - using _is_select = std::true_type; using _requires_braces = std::true_type; - using _value_type = typename detail::select_policies_t::_value_type; - using _name_t = typename _column_list_t::_name_t; + using _name_t = typename _result_type_provider::_name_t; // Constructors select_t() @@ -198,7 +174,7 @@ namespace sqlpp template struct _pseudo_table_t { - using table = typename _column_list_t::template _pseudo_table_t; + using table = typename _result_type_provider::template _pseudo_table_t; using alias = typename table::template _alias_t; }; @@ -212,7 +188,7 @@ namespace sqlpp const _dynamic_names_t& get_dynamic_names() const { - return static_cast(*this)._dynamic_columns._dynamic_expression_names; + return static_cast(*this)._dynamic_columns._dynamic_expression_names; } static constexpr size_t _get_static_no_of_parameters() @@ -227,7 +203,7 @@ namespace sqlpp size_t get_no_of_result_columns() const { - return _column_list_t::static_size() + get_dynamic_names().size(); + return _result_type_provider::static_size() + get_dynamic_names().size(); } void _check_consistency() const diff --git a/tests/FunctionTest.cpp b/tests/FunctionTest.cpp index bc02891b..e668a668 100644 --- a/tests/FunctionTest.cpp +++ b/tests/FunctionTest.cpp @@ -190,7 +190,6 @@ int main() { using S = decltype(select(t.alpha).from(t)); static_assert(sqlpp::is_numeric_t::value, "type requirement"); - static_assert(sqlpp::is_numeric_t::value, "type requirement"); using TI = decltype(any(select(t.alpha).from(t))); using TT = decltype(any(select(t.beta).from(t)));