diff --git a/README.md b/README.md index 145c60b3..d6ed52e9 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,7 @@ or more base dimensions: ```cpp template -struct dimension { - using base_type = dimension; -}; +struct dimension : upcastable> {}; ``` `units::Dimension` is a Concept that is satisfied by a type that is empty and publicly @@ -173,8 +171,7 @@ struct merge_dimension { ```cpp template requires (R::num > 0) -struct unit { - using base_type = unit; +struct unit : upcastable> { using dimension = D; using ratio = R; }; @@ -333,7 +330,7 @@ and are not arguably much easier to understand thus provide better user experience. Upcasting capability is provided through dedicated `upcasting_traits` and by `base_type` member -type in `dimension` and `unit` class templates. +type in `upcastable` class template. ```cpp template diff --git a/src/include/units/bits/tools.h b/src/include/units/bits/tools.h index 0c3389dd..56524e53 100644 --- a/src/include/units/bits/tools.h +++ b/src/include/units/bits/tools.h @@ -110,6 +110,13 @@ namespace units { template using common_ratio_t = typename common_ratio::type; + // upcastable + + template + struct upcastable { + using base_type = BaseType; + }; + // upcasting_traits template diff --git a/src/include/units/dimension.h b/src/include/units/dimension.h index 89f0178e..5f4d5e54 100644 --- a/src/include/units/dimension.h +++ b/src/include/units/dimension.h @@ -71,7 +71,7 @@ namespace units { struct exp_greater_equal : std::bool_constant<(E1::value >= E2::value)> { }; -// exp_invert + // exp_invert template struct exp_invert; @@ -87,9 +87,7 @@ namespace units { // dimension template - struct dimension { - using base_type = dimension; - }; + struct dimension : upcastable> {}; // is_dimension namespace detail { diff --git a/src/include/units/unit.h b/src/include/units/unit.h index 501c7844..42e338b0 100644 --- a/src/include/units/unit.h +++ b/src/include/units/unit.h @@ -29,8 +29,7 @@ namespace units { template requires (R::num > 0) - struct unit { - using base_type = unit; + struct unit : upcastable> { using dimension = D; using ratio = R; };