From 9452cf5f3ca211c5389acd0f275f7b80b5a5ad14 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Tue, 6 Aug 2019 10:35:43 +0200 Subject: [PATCH] Concepts usage removed from deduced template arguments and partial specializations --- src/include/units/dimension.h | 14 ++++----- src/include/units/quantity.h | 56 ++++++++++++++++++----------------- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/src/include/units/dimension.h b/src/include/units/dimension.h index 57646242..31eaf8bb 100644 --- a/src/include/units/dimension.h +++ b/src/include/units/dimension.h @@ -89,7 +89,7 @@ namespace std::experimental::units { template inline constexpr bool is_dimension = false; - template + template inline constexpr bool is_dimension> = true; } // namespace detail @@ -105,7 +105,7 @@ namespace std::experimental::units { template struct dim_invert; - template + template struct dim_invert> : std::type_identity...>>> {}; template @@ -127,18 +127,18 @@ namespace std::experimental::units { using type = dimension<>; }; - template + template struct dim_consolidate> { using type = dimension; }; - template + template struct dim_consolidate> { using rest = dim_consolidate_t>; using type = conditional>, dimension, type_list_push_front>; }; - template + template struct dim_consolidate, exp, ERest...>> { using type = conditional>, dim_consolidate_t, ERest...>>>; @@ -167,7 +167,7 @@ namespace std::experimental::units { template struct dimension_multiply; - template + template struct dimension_multiply, dimension> : std::type_identity, dimension>>> {}; template @@ -178,7 +178,7 @@ namespace std::experimental::units { template struct dimension_divide; - template + template struct dimension_divide, dimension> : dimension_multiply, dimension...>> { }; diff --git a/src/include/units/quantity.h b/src/include/units/quantity.h index 5d3d9471..abc91be8 100644 --- a/src/include/units/quantity.h +++ b/src/include/units/quantity.h @@ -35,6 +35,8 @@ namespace std::experimental::units { template inline constexpr bool is_quantity = false; + // partial specialization below after the first quantity forward declaration + } template @@ -50,7 +52,7 @@ namespace std::experimental::units { namespace detail { - template + template inline constexpr bool is_quantity> = true; } // namespace detail @@ -59,12 +61,12 @@ namespace std::experimental::units { template struct common_quantity; - template + template struct common_quantity, quantity, Rep> { using type = quantity; }; - template + template requires std::Same struct common_quantity, quantity, Rep> { using type = quantity>>, Rep>; @@ -82,9 +84,9 @@ namespace std::experimental::units { namespace detail { - template + template struct quantity_cast_impl { - template + template static constexpr To cast(const Q& q) { return To(static_cast(static_cast(q.count()) * static_cast(CR::num) / @@ -92,7 +94,7 @@ namespace std::experimental::units { } }; - template + template struct quantity_cast_impl { template static constexpr To cast(const Q& q) @@ -101,7 +103,7 @@ namespace std::experimental::units { } }; - template + template struct quantity_cast_impl { template static constexpr To cast(const Q& q) @@ -110,7 +112,7 @@ namespace std::experimental::units { } }; - template + template struct quantity_cast_impl { template static constexpr To cast(const Q& q) @@ -121,7 +123,7 @@ namespace std::experimental::units { } // namespace detail - template + template requires std::Same constexpr To quantity_cast(const quantity& q) { @@ -237,7 +239,7 @@ namespace std::experimental::units { }; // clang-format off - template + template [[nodiscard]] constexpr Quantity operator+(const quantity& lhs, const quantity& rhs) requires std::Same @@ -247,7 +249,7 @@ namespace std::experimental::units { return ret(ret(lhs).count() + ret(rhs).count()); } - template + template [[nodiscard]] constexpr Quantity operator-(const quantity& lhs, const quantity& rhs) requires std::Same @@ -257,7 +259,7 @@ namespace std::experimental::units { return ret(ret(lhs).count() - ret(rhs).count()); } -// template +// template template [[nodiscard]] constexpr Quantity operator*(const quantity& q, const Rep2& v) @@ -268,7 +270,7 @@ namespace std::experimental::units { return ret(ret(q).count() * v); } - //template +// template template [[nodiscard]] constexpr Quantity operator*(const Rep1& v, const quantity& q) @@ -277,7 +279,7 @@ namespace std::experimental::units { return q * v; } - template + template [[nodiscard]] constexpr Scalar operator*(const quantity& lhs, const quantity& rhs) requires std::Same> @@ -287,7 +289,7 @@ namespace std::experimental::units { return common_rep(lhs.count()) * common_rep(rhs.count()) * common_rep(ratio::num) / common_rep(ratio::den); } - template + template [[nodiscard]] constexpr Quantity operator*(const quantity& lhs, const quantity& rhs) requires (!std::Same>) && @@ -300,7 +302,7 @@ namespace std::experimental::units { return ret(lhs.count() * rhs.count()); } -// template +// template template [[nodiscard]] constexpr Quantity operator/(const Rep1& v, const quantity& q) @@ -315,7 +317,7 @@ namespace std::experimental::units { return ret(v / den(q).count()); } -// template +// template template [[nodiscard]] constexpr Quantity operator/(const quantity& q, const Rep2& v) @@ -328,7 +330,7 @@ namespace std::experimental::units { return ret(ret(q).count() / v); } - template + template [[nodiscard]] constexpr Scalar operator/(const quantity& lhs, const quantity& rhs) requires std::Same @@ -340,7 +342,7 @@ namespace std::experimental::units { return cq(lhs).count() / cq(rhs).count(); } - template + template [[nodiscard]] constexpr Quantity operator/(const quantity& lhs, const quantity& rhs) requires (!std::Same) && @@ -355,7 +357,7 @@ namespace std::experimental::units { return ret(lhs.count() / rhs.count()); } - template + template [[nodiscard]] constexpr Quantity operator%(const quantity& q, const Rep2& v) { @@ -364,7 +366,7 @@ namespace std::experimental::units { return ret(ret(q).count() % v); } - template + template [[nodiscard]] constexpr Quantity operator%(const quantity& lhs, const quantity& rhs) { @@ -375,7 +377,7 @@ namespace std::experimental::units { // clang-format on - template + template [[nodiscard]] constexpr bool operator==(const quantity& lhs, const quantity& rhs) requires std::Same { @@ -383,14 +385,14 @@ namespace std::experimental::units { return ct(lhs).count() == ct(rhs).count(); } - template + template [[nodiscard]] constexpr bool operator!=(const quantity& lhs, const quantity& rhs) requires std::Same { return !(lhs == rhs); } - template + template [[nodiscard]] constexpr bool operator<(const quantity& lhs, const quantity& rhs) requires std::Same { @@ -398,21 +400,21 @@ namespace std::experimental::units { return ct(lhs).count() < ct(rhs).count(); } - template + template [[nodiscard]] constexpr bool operator<=(const quantity& lhs, const quantity& rhs) requires std::Same { return !(rhs < lhs); } - template + template [[nodiscard]] constexpr bool operator>(const quantity& lhs, const quantity& rhs) requires std::Same { return rhs < lhs; } - template + template [[nodiscard]] constexpr bool operator>=(const quantity& lhs, const quantity& rhs) requires std::Same {