From a452438cad709d828c162cb188ab07f98b9aae31 Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 1 Nov 2015 19:26:49 +0100 Subject: [PATCH] Removed the slightly annoying _tag from data_types --- .../sqlpp11/data_types/boolean/data_type.h | 3 +- .../sqlpp11/data_types/day_point/data_type.h | 7 ++- .../data_types/floating_point/data_type.h | 3 +- .../sqlpp11/data_types/integral/data_type.h | 3 +- include/sqlpp11/data_types/text/data_type.h | 3 +- .../sqlpp11/data_types/time_point/data_type.h | 5 +- include/sqlpp11/no_value.h | 2 +- include/sqlpp11/type_traits.h | 51 +++++++++++++------ 8 files changed, 45 insertions(+), 32 deletions(-) diff --git a/include/sqlpp11/data_types/boolean/data_type.h b/include/sqlpp11/data_types/boolean/data_type.h index 855bb50e..1e58810f 100644 --- a/include/sqlpp11/data_types/boolean/data_type.h +++ b/include/sqlpp11/data_types/boolean/data_type.h @@ -33,8 +33,7 @@ namespace sqlpp { struct boolean { - using _traits = make_traits; - using _tag = tag::is_boolean; + using _traits = make_traits; using _cpp_value_type = bool; template diff --git a/include/sqlpp11/data_types/day_point/data_type.h b/include/sqlpp11/data_types/day_point/data_type.h index abd7ba8a..0a2b1df1 100644 --- a/include/sqlpp11/data_types/day_point/data_type.h +++ b/include/sqlpp11/data_types/day_point/data_type.h @@ -34,14 +34,13 @@ namespace sqlpp { struct day_point { - using _traits = make_traits; - using _tag = tag::is_date; + using _traits = make_traits; using _cpp_value_type = ::sqlpp::chrono::day_point; template - using _is_valid_operand = is_time_point_t; + using _is_valid_operand = is_day_or_time_point_t; template - using _is_valid_assignment_operand = is_date_t; + using _is_valid_assignment_operand = is_day_point_t; }; } #endif diff --git a/include/sqlpp11/data_types/floating_point/data_type.h b/include/sqlpp11/data_types/floating_point/data_type.h index d4c43887..418b89bb 100644 --- a/include/sqlpp11/data_types/floating_point/data_type.h +++ b/include/sqlpp11/data_types/floating_point/data_type.h @@ -33,8 +33,7 @@ namespace sqlpp { struct floating_point { - using _traits = make_traits; - using _tag = tag::is_floating_point; + using _traits = make_traits; using _cpp_value_type = double; template diff --git a/include/sqlpp11/data_types/integral/data_type.h b/include/sqlpp11/data_types/integral/data_type.h index 4ffce0c4..550421d4 100644 --- a/include/sqlpp11/data_types/integral/data_type.h +++ b/include/sqlpp11/data_types/integral/data_type.h @@ -33,8 +33,7 @@ namespace sqlpp { struct integral { - using _traits = make_traits; - using _tag = tag::is_integral; + using _traits = make_traits; using _cpp_value_type = int64_t; template diff --git a/include/sqlpp11/data_types/text/data_type.h b/include/sqlpp11/data_types/text/data_type.h index e9644357..7356342d 100644 --- a/include/sqlpp11/data_types/text/data_type.h +++ b/include/sqlpp11/data_types/text/data_type.h @@ -33,8 +33,7 @@ namespace sqlpp { struct text { - using _traits = make_traits; - using _tag = tag::is_text; + using _traits = make_traits; using _cpp_value_type = std::string; template diff --git a/include/sqlpp11/data_types/time_point/data_type.h b/include/sqlpp11/data_types/time_point/data_type.h index f64be70d..89e02619 100644 --- a/include/sqlpp11/data_types/time_point/data_type.h +++ b/include/sqlpp11/data_types/time_point/data_type.h @@ -34,12 +34,11 @@ namespace sqlpp { struct time_point { - using _traits = make_traits; - using _tag = tag::is_date_time; + using _traits = make_traits; using _cpp_value_type = ::sqlpp::chrono::mus_point; template - using _is_valid_operand = is_time_point_t; + using _is_valid_operand = is_day_or_time_point_t; }; } #endif diff --git a/include/sqlpp11/no_value.h b/include/sqlpp11/no_value.h index ee5f2715..68c842dc 100644 --- a/include/sqlpp11/no_value.h +++ b/include/sqlpp11/no_value.h @@ -35,7 +35,7 @@ namespace sqlpp { struct no_value_t { - using _tag = void; + using _traits = make_traits; }; template diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index 797bec57..33b85839 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -62,6 +62,39 @@ namespace sqlpp template using column_spec_can_be_null_t = typename detail::column_spec_can_be_null_impl::type; +#define SQLPP_VALUE_TYPE_GENERATOR(name) \ + struct name; \ + namespace detail \ + { \ + template \ + struct is_##name##_impl \ + { \ + using type = std::false_type; \ + }; \ + template \ + struct is_##name##_impl< \ + T, \ + typename std::enable_if::value>::type> \ + { \ + using type = std::true_type; \ + }; \ + } \ + template \ + using is_##name##_t = typename detail::is_##name##_impl::type; + + SQLPP_VALUE_TYPE_GENERATOR(boolean) + SQLPP_VALUE_TYPE_GENERATOR(day_point) + SQLPP_VALUE_TYPE_GENERATOR(time_point) + SQLPP_VALUE_TYPE_GENERATOR(integral) + SQLPP_VALUE_TYPE_GENERATOR(floating_point) + template + using is_numeric_t = logic::any_t::value, is_floating_point_t::value>; + + template + using is_day_or_time_point_t = logic::any_t::value, is_time_point_t::value>; + + SQLPP_VALUE_TYPE_GENERATOR(text) + #define SQLPP_VALUE_TRAIT_GENERATOR(name) \ namespace tag \ { \ @@ -87,22 +120,8 @@ namespace sqlpp template \ using name##_t = typename detail::name##_impl::type; - SQLPP_VALUE_TRAIT_GENERATOR(is_value_type) SQLPP_VALUE_TRAIT_GENERATOR(is_sql_null) - SQLPP_VALUE_TRAIT_GENERATOR(is_boolean) - SQLPP_VALUE_TRAIT_GENERATOR(is_date) - SQLPP_VALUE_TRAIT_GENERATOR(is_date_time) - SQLPP_VALUE_TRAIT_GENERATOR(is_integral) - SQLPP_VALUE_TRAIT_GENERATOR(is_floating_point) - template - using is_numeric_t = logic::any_t::value, - detail::is_element_of::value>; - - template - using is_time_point_t = logic::any_t::value, - detail::is_element_of::value>; - - SQLPP_VALUE_TRAIT_GENERATOR(is_text) + SQLPP_VALUE_TRAIT_GENERATOR(is_value_type) SQLPP_VALUE_TRAIT_GENERATOR(is_wrapped_value) SQLPP_VALUE_TRAIT_GENERATOR(is_selectable) SQLPP_VALUE_TRAIT_GENERATOR(is_expression) @@ -301,7 +320,7 @@ namespace sqlpp struct make_traits { using _value_type = ValueType; - using _tags = detail::make_type_set_t; + using _tags = detail::make_type_set_t; }; struct aggregate_function