From 7fb8b456bc2e087c87a73d6d3554748b38ec2525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johel=20Ernesto=20Guerrero=20Pe=C3=B1a?= Date: Mon, 7 Sep 2020 22:25:35 -0400 Subject: [PATCH] refactor: simplify dimension_unit --- src/include/units/concepts.h | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/include/units/concepts.h b/src/include/units/concepts.h index 686e9f68..cbf822a0 100644 --- a/src/include/units/concepts.h +++ b/src/include/units/concepts.h @@ -165,17 +165,13 @@ concept Dimension = BaseDimension || DerivedDimension; namespace detail { template -struct dimension_unit_impl; - -template -struct dimension_unit_impl { - using type = TYPENAME D::base_unit; -}; - -template -struct dimension_unit_impl { - using type = TYPENAME D::coherent_unit; -}; +auto default_unit() +{ + if constexpr (BaseDimension) + return TYPENAME D::base_unit{}; + else + return TYPENAME D::coherent_unit{}; +} } // namespace detail @@ -188,7 +184,7 @@ struct dimension_unit_impl { * @tparam D Dimension type to get the unit from. */ template -using dimension_unit = TYPENAME detail::dimension_unit_impl::type; +using dimension_unit = decltype(detail::default_unit()); /** * @brief A concept matching only units of a specified dimension.