From 2fddb494d31692fa4d515afb82509871b27e95c4 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Fri, 4 Oct 2019 16:22:49 +0200 Subject: [PATCH] `_t` postfix removed from the interface (resolves #9) --- doc/DESIGN.md | 8 +- src/include/units/dimension.h | 173 ++++++++++++++------------- src/include/units/math.h | 4 +- src/include/units/quantity.h | 50 ++++---- test/unit_test/test_custom_units.cpp | 4 +- test/unit_test/test_dimension.cpp | 62 +++++----- test/unit_test/test_quantity.cpp | 6 +- test/unit_test/test_type_list.cpp | 8 +- 8 files changed, 167 insertions(+), 148 deletions(-) diff --git a/doc/DESIGN.md b/doc/DESIGN.md index feb52651..6efcc799 100644 --- a/doc/DESIGN.md +++ b/doc/DESIGN.md @@ -221,7 +221,7 @@ struct dimension_multiply, dimension> { }; template -using dimension_multiply_t = dimension_multiply::type; +using dimension_multiply = dimension_multiply::type; ``` @@ -343,12 +343,12 @@ public: [[nodiscard]] static constexpr quantity one() noexcept { return quantity(quantity_values::one()); } template - requires std::same_as> + requires std::same_as> [[nodiscard]] constexpr Scalar operator*(const quantity& lhs, const quantity& rhs); template - requires (!std::same_as>) && + requires (!std::same_as>) && (treat_as_floating_point || (std::ratio_multiply::den == 1)) [[nodiscard]] constexpr Quantity operator*(const quantity& lhs, @@ -579,7 +579,7 @@ for a given specialization in a base type. For example to determine a downcasted type of a quantity multiply operation the following can be done: ```cpp -using dim = dimension_multiply_t; +using dim = dimension_multiply; using common_rep = decltype(lhs.count() * rhs.count()); using ret = quantity>>, common_rep>; ``` diff --git a/src/include/units/dimension.h b/src/include/units/dimension.h index 55b9e286..3421028b 100644 --- a/src/include/units/dimension.h +++ b/src/include/units/dimension.h @@ -90,7 +90,6 @@ namespace units { detail::is_dimension>; // exp - template requires BaseDimension || Dimension struct exp { @@ -108,68 +107,70 @@ namespace units { } // namespace detail // exp_less - template struct exp_less : base_dimension_less { }; // exp_invert + namespace detail { + + template + struct exp_invert_impl; + + template + struct exp_invert_impl> { + using type = exp; + }; + + } template - struct exp_invert; - - template - struct exp_invert> { - using type = exp; - }; - - template - using exp_invert_t = exp_invert::type; + using exp_invert = detail::exp_invert_impl::type; // exp_multiply + namespace detail { + + template + struct exp_multiply_impl { + using r1 = ratio; + using r2 = ratio; + using r = ratio_multiply; + using type = exp; + }; + + } template - struct exp_multiply { - using r1 = ratio; - using r2 = ratio; - using r = ratio_multiply; - using type = exp; - }; - - template - using exp_multiply_t = exp_multiply::type; + using exp_multiply = detail::exp_multiply_impl::type; // dimension - template struct dimension : downcast_base> {}; // same_dim - template inline constexpr bool same_dim = std::is_same_v; // dim_invert + namespace detail { - template - struct dim_invert; + template + struct dim_invert_impl; - template - struct dim_invert> : std::type_identity...>>> {}; + template + struct dim_invert_impl> : std::type_identity...>>> {}; + + } template - using dim_invert_t = dim_invert>::type; + using dim_invert = detail::dim_invert_impl>::type; // make_dimension - namespace detail { template struct dim_consolidate; - template - using dim_consolidate_t = dim_consolidate::type; - template<> struct dim_consolidate> { using type = dimension<>; @@ -182,7 +183,7 @@ namespace units { template struct dim_consolidate> { - using type = type_list_push_front>, E1>; + using type = type_list_push_front>::type, E1>; }; template @@ -191,16 +192,13 @@ namespace units { using r1 = std::ratio; using r2 = std::ratio; using r = std::ratio_add; - using type = conditional>, - dim_consolidate_t, ERest...>>>; + using type = conditional>::type, + typename dim_consolidate, ERest...>>::type>; }; template struct extract; - template - using extract_t = extract::type; - template<> struct extract<> { using type = dimension<>; @@ -208,88 +206,99 @@ namespace units { template struct extract, ERest...> { - using type = type_list_push_front, exp>; + using type = type_list_push_front::type, exp>; }; template struct extract, Num, Den>, ERest...> { - using type = type_list_push_front, exp_multiply_t...>; + using type = type_list_push_front::type, exp_multiply...>; }; template struct extract, ERest...> { - using type = extract_t, Num, Den>, ERest...>; + using type = extract, Num, Den>, ERest...>::type; }; template struct make_dimension { - using type = detail::dim_consolidate_t, exp_less>>; + using type = detail::dim_consolidate::type, exp_less>>::type; }; - template - using make_dimension_t = make_dimension::type; - } // namespace detail // derived_dimension - template - struct derived_dimension : downcast_helper> {}; + struct derived_dimension : downcast_helper::type> {}; // merge_dimension + namespace detail { + + template + struct merge_dimension_impl { + using type = detail::dim_consolidate>::type; + }; + + } template - struct merge_dimension { - using type = detail::dim_consolidate_t>; - }; - - template - using merge_dimension_t = merge_dimension::type; + using merge_dimension = detail::merge_dimension_impl::type; // dimension_multiply + namespace detail { + + template + struct dimension_multiply_impl; + + template + struct dimension_multiply_impl, dimension> : std::type_identity, dimension>>> {}; + + } template - struct dimension_multiply; - - template - struct dimension_multiply, dimension> : std::type_identity, dimension>>> {}; - - template - using dimension_multiply_t = dimension_multiply::type; + using dimension_multiply = detail::dimension_multiply_impl::type; // dimension_divide + namespace detail { + + template + struct dimension_divide_impl; + + template + struct dimension_divide_impl, dimension> + : dimension_multiply_impl, dimension...>> { + }; + + } template - struct dimension_divide; - - template - struct dimension_divide, dimension> - : dimension_multiply, dimension...>> { - }; - - template - using dimension_divide_t = dimension_divide::type; + using dimension_divide = detail::dimension_divide_impl::type; // dimension_sqrt + namespace detail { + + template + struct dimension_sqrt_impl; + + template + struct dimension_sqrt_impl> : std::type_identity...>>> {}; + + } template - struct dimension_sqrt; - - template - struct dimension_sqrt> : std::type_identity...>>> {}; - - template - using dimension_sqrt_t = dimension_sqrt::type; + using dimension_sqrt = detail::dimension_sqrt_impl::type; // dimension_pow + namespace detail { + + template + struct dimension_pow_impl; + + template + struct dimension_pow_impl, N> : std::type_identity...>>> {}; + + } template - struct dimension_pow; - - template - struct dimension_pow, N> : std::type_identity...>>> {}; - - template - using dimension_pow_t = dimension_pow::type; + using dimension_pow = detail::dimension_pow_impl::type; } // namespace units diff --git a/src/include/units/math.h b/src/include/units/math.h index d13aa4c5..46628653 100644 --- a/src/include/units/math.h +++ b/src/include/units/math.h @@ -30,7 +30,7 @@ namespace units { template inline Quantity pow(const quantity& q) noexcept { - using dim = dimension_pow_t; + using dim = dimension_pow; using r = ratio_pow; return quantity>, Rep>(static_cast(std::pow(q.count(), N))); } @@ -38,7 +38,7 @@ namespace units { template inline Quantity sqrt(const quantity& q) noexcept { - using dim = dimension_sqrt_t; + using dim = dimension_sqrt; using r = ratio_sqrt; return quantity>, Rep>(static_cast(std::sqrt(q.count()))); } diff --git a/src/include/units/quantity.h b/src/include/units/quantity.h index 4819bae9..13f7665c 100644 --- a/src/include/units/quantity.h +++ b/src/include/units/quantity.h @@ -60,22 +60,26 @@ namespace units { } // namespace detail // common_quantity - template - struct common_quantity; + namespace detail { - template - struct common_quantity, quantity, Rep> { - using type = quantity; - }; + template + struct common_quantity_impl; - template - requires same_dim - struct common_quantity, quantity, Rep> { - using type = quantity>>, Rep>; - }; + template + struct common_quantity_impl, quantity, Rep> { + using type = quantity; + }; + + template + requires same_dim + struct common_quantity_impl, quantity, Rep> { + using type = quantity>>, Rep>; + }; + + } template> - using common_quantity_t = common_quantity::type; + using common_quantity = detail::common_quantity_impl::type; // treat_as_floating_point @@ -280,7 +284,7 @@ namespace units { requires same_dim { using common_rep = decltype(lhs.count() + rhs.count()); - using ret = common_quantity_t, quantity, common_rep>; + using ret = common_quantity, quantity, common_rep>; return ret(ret(lhs).count() + ret(rhs).count()); } @@ -290,7 +294,7 @@ namespace units { requires same_dim { using common_rep = decltype(lhs.count() - rhs.count()); - using ret = common_quantity_t, quantity, common_rep>; + using ret = common_quantity, quantity, common_rep>; return ret(ret(lhs).count() - ret(rhs).count()); } @@ -317,7 +321,7 @@ namespace units { template [[nodiscard]] constexpr Scalar operator*(const quantity& lhs, const quantity& rhs) - requires same_dim> + requires same_dim> { using common_rep = decltype(lhs.count() * rhs.count()); using ratio = ratio_multiply; @@ -327,11 +331,11 @@ namespace units { template [[nodiscard]] constexpr Quantity operator*(const quantity& lhs, const quantity& rhs) - requires (!same_dim>) && + requires (!same_dim>) && (treat_as_floating_point || (std::ratio_multiply::den == 1)) { - using dim = dimension_multiply_t; + using dim = dimension_multiply; using common_rep = decltype(lhs.count() * rhs.count()); using ret = quantity>>, common_rep>; return ret(lhs.count() * rhs.count()); @@ -345,7 +349,7 @@ namespace units { { Expects(q != std::remove_cvref_t(0)); - using dim = dim_invert_t; + using dim = dim_invert; using common_rep = decltype(v / q.count()); using ret = quantity>>, common_rep>; using den = quantity; @@ -373,7 +377,7 @@ namespace units { Expects(rhs != std::remove_cvref_t(0)); using common_rep = decltype(lhs.count() / rhs.count()); - using cq = common_quantity_t, quantity, common_rep>; + using cq = common_quantity, quantity, common_rep>; return cq(lhs).count() / cq(rhs).count(); } @@ -387,7 +391,7 @@ namespace units { Expects(rhs != std::remove_cvref_t(0)); using common_rep = decltype(lhs.count() / rhs.count()); - using dim = dimension_divide_t; + using dim = dimension_divide; using ret = quantity>>, common_rep>; return ret(lhs.count() / rhs.count()); } @@ -406,7 +410,7 @@ namespace units { const quantity& rhs) { using common_rep = decltype(lhs.count() % rhs.count()); - using ret = common_quantity_t, quantity, common_rep>; + using ret = common_quantity, quantity, common_rep>; return ret(ret(lhs).count() % ret(rhs).count()); } @@ -416,7 +420,7 @@ namespace units { [[nodiscard]] constexpr bool operator==(const quantity& lhs, const quantity& rhs) requires same_dim { - using ct = common_quantity_t, quantity>; + using ct = common_quantity, quantity>; return ct(lhs).count() == ct(rhs).count(); } @@ -431,7 +435,7 @@ namespace units { [[nodiscard]] constexpr bool operator<(const quantity& lhs, const quantity& rhs) requires same_dim { - using ct = common_quantity_t, quantity>; + using ct = common_quantity, quantity>; return ct(lhs).count() < ct(rhs).count(); } diff --git a/test/unit_test/test_custom_units.cpp b/test/unit_test/test_custom_units.cpp index 000a04e3..f2ac51fd 100644 --- a/test/unit_test/test_custom_units.cpp +++ b/test/unit_test/test_custom_units.cpp @@ -72,8 +72,8 @@ namespace { namespace { - static_assert(std::is_same_v, amplitude_spectral_density>); - static_assert(std::is_same_v, power_spectral_density>); + static_assert(std::is_same_v, amplitude_spectral_density>); + static_assert(std::is_same_v, power_spectral_density>); static_assert(std::is_same_v(quantity(4))), decltype(quantity(16))>); static_assert(std::is_same_v(16))), decltype(quantity(4))>); diff --git a/test/unit_test/test_dimension.cpp b/test/unit_test/test_dimension.cpp index c117d5a9..78d92dba 100644 --- a/test/unit_test/test_dimension.cpp +++ b/test/unit_test/test_dimension.cpp @@ -34,59 +34,65 @@ namespace { // exp_invert - static_assert(std::is_same_v>, exp>); - static_assert(std::is_same_v>, exp>); + static_assert(std::is_same_v>, exp>); + static_assert(std::is_same_v>, exp>); // extract template struct typeinfo; - static_assert(std::is_same_v, dimension<>>); - static_assert(std::is_same_v>, dimension>>); - static_assert(std::is_same_v, exp>, dimension, exp>>); + template + using extract = detail::extract::type; + + static_assert(std::is_same_v, dimension<>>); + static_assert(std::is_same_v>, dimension>>); + static_assert(std::is_same_v, exp>, dimension, exp>>); using dim0 = dimension<>; using dim1 = dimension>; using dim2 = dimension, exp>; - static_assert(std::is_same_v, exp>, dimension>>); - static_assert(std::is_same_v, exp>, dimension, exp>>); - static_assert(std::is_same_v, exp, exp>, dimension, exp, exp, exp>>); + static_assert(std::is_same_v, exp>, dimension>>); + static_assert(std::is_same_v, exp>, dimension, exp>>); + static_assert(std::is_same_v, exp, exp>, dimension, exp, exp, exp>>); // make_dimension - static_assert(std::is_same_v>, dimension>>); - static_assert(std::is_same_v, exp>, dimension, exp>>); - static_assert(std::is_same_v, exp>, dimension, exp>>); - static_assert(std::is_same_v, exp>, dimension>>); - static_assert(std::is_same_v, exp>, dimension<>>); - static_assert(std::is_same_v, exp>, dimension>>); - static_assert(std::is_same_v, exp>, dimension>>); - static_assert(std::is_same_v, exp>, dimension>>); + template + using make_dimension = detail::make_dimension::type; - static_assert(std::is_same_v, exp, exp, exp>, dimension, exp>>); + static_assert(std::is_same_v>, dimension>>); + static_assert(std::is_same_v, exp>, dimension, exp>>); + static_assert(std::is_same_v, exp>, dimension, exp>>); + static_assert(std::is_same_v, exp>, dimension>>); + static_assert(std::is_same_v, exp>, dimension<>>); + static_assert(std::is_same_v, exp>, dimension>>); + static_assert(std::is_same_v, exp>, dimension>>); + static_assert(std::is_same_v, exp>, dimension>>); + + static_assert(std::is_same_v, exp, exp, exp>, dimension, exp>>); static_assert( - std::is_same_v, exp, exp, exp>, dimension, exp>>); + std::is_same_v, exp, exp, exp>, dimension, exp>>); - static_assert(std::is_same_v, exp, exp>, dimension>>); - static_assert(std::is_same_v, exp, exp>, dimension>>); - static_assert(std::is_same_v, exp, exp>, dimension>>); - static_assert(std::is_same_v, exp, exp, exp>, dimension<>>); + static_assert(std::is_same_v, exp, exp>, dimension>>); + static_assert(std::is_same_v, exp, exp>, dimension>>); + static_assert(std::is_same_v, exp, exp>, dimension>>); + static_assert(std::is_same_v, exp, exp, exp>, dimension<>>); // dimension_multiply static_assert( - std::is_same_v>, dimension>>, dimension, exp>>); - static_assert(std::is_same_v, exp, exp>, dimension>>, + std::is_same_v>, dimension>>, dimension, exp>>); + static_assert(std::is_same_v, exp, exp>, dimension>>, dimension, exp, exp, exp>>); - static_assert(std::is_same_v, exp, exp>, dimension>>, + static_assert(std::is_same_v, exp, exp>, dimension>>, dimension, exp, exp>>); - static_assert(std::is_same_v, exp, exp>, dimension>>, + static_assert(std::is_same_v, exp, exp>, dimension>>, dimension, exp>>); // dimension_divide static_assert( - std::is_same_v>, dimension>>, dimension, exp>>); - static_assert(std::is_same_v>, dimension>>, dimension<>>); + std::is_same_v>, dimension>>, dimension, exp>>); + static_assert(std::is_same_v>, dimension>>, dimension<>>); } // namespace diff --git a/test/unit_test/test_quantity.cpp b/test/unit_test/test_quantity.cpp index 8d580c80..2e789793 100644 --- a/test/unit_test/test_quantity.cpp +++ b/test/unit_test/test_quantity.cpp @@ -263,9 +263,9 @@ namespace { // common_quantity - static_assert(std::is_same_v, quantity>, quantity>); - static_assert(std::is_same_v, quantity>, quantity>); - static_assert(std::is_same_v, quantity>, quantity>); + static_assert(std::is_same_v, quantity>, quantity>); + static_assert(std::is_same_v, quantity>, quantity>); + static_assert(std::is_same_v, quantity>, quantity>); // quantity_cast diff --git a/test/unit_test/test_type_list.cpp b/test/unit_test/test_type_list.cpp index dd89b836..e47df4e6 100644 --- a/test/unit_test/test_type_list.cpp +++ b/test/unit_test/test_type_list.cpp @@ -93,10 +93,10 @@ namespace { // type_list_sort template - using exp_sort_t = type_list_sort; + using exp_sort = type_list_sort; - static_assert(std::is_same_v>>, dimension>>); - static_assert(std::is_same_v, exp>>, dimension, exp>>); - static_assert(std::is_same_v, exp>>, dimension, exp>>); + static_assert(std::is_same_v>>, dimension>>); + static_assert(std::is_same_v, exp>>, dimension, exp>>); + static_assert(std::is_same_v, exp>>, dimension, exp>>); } // namespace