From 58e1eefd3b4a18fd3daeee31bb80fb3708998bdd Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Thu, 15 Nov 2018 05:29:01 +0100 Subject: [PATCH] Inheritance hierarchy helpers for dimension and unit made more descriptive --- src/include/units/dimension.h | 14 ++++++++------ src/include/units/si/frequency.h | 14 +++++++------- src/include/units/si/length.h | 10 +++++----- src/include/units/si/time.h | 14 +++++++------- src/include/units/si/velocity.h | 8 ++++---- src/include/units/unit.h | 7 ++++--- 6 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/include/units/dimension.h b/src/include/units/dimension.h index bcee7d02..489166f7 100644 --- a/src/include/units/dimension.h +++ b/src/include/units/dimension.h @@ -89,7 +89,9 @@ namespace units { // dimension template - struct dimension : std::type_identity> {}; + struct dimension { + using base_type = dimension; + }; // is_dimension namespace detail { @@ -103,8 +105,8 @@ namespace units { template concept bool Dimension = std::is_empty_v && - detail::is_dimension && - DerivedFrom; + detail::is_dimension && + DerivedFrom; // dim_invert @@ -116,7 +118,7 @@ namespace units { struct dim_invert> : std::type_identity...>>> {}; template - using dim_invert_t = typename dim_invert::type; + using dim_invert_t = typename dim_invert::type; // make_dimension @@ -171,7 +173,7 @@ namespace units { struct dimension_multiply, dimension> : std::type_identity>> {}; template - using dimension_multiply_t = typename dimension_multiply::type; + using dimension_multiply_t = typename dimension_multiply::type; // dimension_divide @@ -184,6 +186,6 @@ namespace units { }; template - using dimension_divide_t = typename dimension_divide::type; + using dimension_divide_t = typename dimension_divide::type; } // namespace units diff --git a/src/include/units/si/frequency.h b/src/include/units/si/frequency.h index 924d3764..6b2efb8b 100644 --- a/src/include/units/si/frequency.h +++ b/src/include/units/si/frequency.h @@ -28,25 +28,25 @@ namespace units { struct dimension_frequency : make_dimension_t> {}; - template<> struct dimension_traits : std::type_identity {}; + template<> struct dimension_traits : std::type_identity {}; struct millihertz : unit {}; - template<> struct unit_traits : std::type_identity {}; + template<> struct unit_traits : std::type_identity {}; struct hertz : unit> {}; - template<> struct unit_traits : std::type_identity {}; + template<> struct unit_traits : std::type_identity {}; struct kilohertz : unit {}; - template<> struct unit_traits : std::type_identity {}; + template<> struct unit_traits : std::type_identity {}; struct megahertz : unit {}; - template<> struct unit_traits : std::type_identity {}; + template<> struct unit_traits : std::type_identity {}; struct gigahertz : unit {}; - template<> struct unit_traits : std::type_identity {}; + template<> struct unit_traits : std::type_identity {}; struct terahertz : unit {}; - template<> struct unit_traits : std::type_identity {}; + template<> struct unit_traits : std::type_identity {}; template using frequency = quantity; diff --git a/src/include/units/si/length.h b/src/include/units/si/length.h index 08b274e5..70755960 100644 --- a/src/include/units/si/length.h +++ b/src/include/units/si/length.h @@ -28,19 +28,19 @@ namespace units { struct dimension_length : make_dimension_t> {}; - template<> struct dimension_traits : std::type_identity {}; + template<> struct dimension_traits : std::type_identity {}; struct millimeter : unit {}; - template<> struct unit_traits : std::type_identity {}; + template<> struct unit_traits : std::type_identity {}; struct centimeter : unit> {}; - template<> struct unit_traits : std::type_identity {}; + template<> struct unit_traits : std::type_identity {}; struct meter : unit> {}; - template<> struct unit_traits : std::type_identity {}; + template<> struct unit_traits : std::type_identity {}; struct kilometer : unit {}; - template<> struct unit_traits : std::type_identity {}; + template<> struct unit_traits : std::type_identity {}; template using length = quantity; diff --git a/src/include/units/si/time.h b/src/include/units/si/time.h index 10f903fa..0db0390c 100644 --- a/src/include/units/si/time.h +++ b/src/include/units/si/time.h @@ -28,25 +28,25 @@ namespace units { struct dimension_time : make_dimension_t> {}; - template<> struct dimension_traits : std::type_identity {}; + template<> struct dimension_traits : std::type_identity {}; struct nanosecond : unit {}; - template<> struct unit_traits : std::type_identity {}; + template<> struct unit_traits : std::type_identity {}; struct microsecond : unit {}; - template<> struct unit_traits : std::type_identity {}; + template<> struct unit_traits : std::type_identity {}; struct millisecond : unit {}; - template<> struct unit_traits : std::type_identity {}; + template<> struct unit_traits : std::type_identity {}; struct second : unit> {}; - template<> struct unit_traits : std::type_identity {}; + template<> struct unit_traits : std::type_identity {}; struct minute : unit> {}; - template<> struct unit_traits : std::type_identity {}; + template<> struct unit_traits : std::type_identity {}; struct hour : unit> {}; - template<> struct unit_traits : std::type_identity {}; + template<> struct unit_traits : std::type_identity {}; template using time = quantity; diff --git a/src/include/units/si/velocity.h b/src/include/units/si/velocity.h index 5b191fac..49dc4ee5 100644 --- a/src/include/units/si/velocity.h +++ b/src/include/units/si/velocity.h @@ -29,16 +29,16 @@ namespace units { struct dimension_velocity : make_dimension_t, exp> {}; - template<> struct dimension_traits : std::type_identity {}; + template<> struct dimension_traits : std::type_identity {}; struct meter_per_second : unit> {}; - template<> struct unit_traits : std::type_identity {}; + template<> struct unit_traits : std::type_identity {}; struct kilometer_per_hour : unit> {}; - template<> struct unit_traits : std::type_identity {}; + template<> struct unit_traits : std::type_identity {}; struct mile_per_hour : unit> {}; - template<> struct unit_traits : std::type_identity {}; + template<> struct unit_traits : std::type_identity {}; template using velocity = quantity; diff --git a/src/include/units/unit.h b/src/include/units/unit.h index 9b31d2e6..51e04992 100644 --- a/src/include/units/unit.h +++ b/src/include/units/unit.h @@ -28,7 +28,8 @@ namespace units { template - struct unit : std::type_identity> { + struct unit { + using base_type = unit; using dimension = D; using ratio = R; static_assert(ratio::num > 0, "ratio must be positive"); @@ -49,8 +50,8 @@ namespace units { template concept bool Unit = std::is_empty_v && - detail::is_unit && - DerivedFrom; + detail::is_unit && + DerivedFrom; // dimension_traits