forked from mpusz/mp-units
upcastable class template added to provide the base class for upcastable classes
This commit is contained in:
@@ -29,9 +29,7 @@ or more base dimensions:
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
template<Exponent... Es>
|
template<Exponent... Es>
|
||||||
struct dimension {
|
struct dimension : upcastable<dimension<Es...>> {};
|
||||||
using base_type = dimension<Es...>;
|
|
||||||
};
|
|
||||||
```
|
```
|
||||||
|
|
||||||
`units::Dimension` is a Concept that is satisfied by a type that is empty and publicly
|
`units::Dimension` is a Concept that is satisfied by a type that is empty and publicly
|
||||||
@@ -173,8 +171,7 @@ struct merge_dimension {
|
|||||||
```cpp
|
```cpp
|
||||||
template<Dimension D, Ratio R>
|
template<Dimension D, Ratio R>
|
||||||
requires (R::num > 0)
|
requires (R::num > 0)
|
||||||
struct unit {
|
struct unit : upcastable<unit<D, R>> {
|
||||||
using base_type = unit<D, R>;
|
|
||||||
using dimension = D;
|
using dimension = D;
|
||||||
using ratio = R;
|
using ratio = R;
|
||||||
};
|
};
|
||||||
@@ -333,7 +330,7 @@ and
|
|||||||
are not arguably much easier to understand thus provide better user experience.
|
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
|
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
|
```cpp
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@@ -110,6 +110,13 @@ namespace units {
|
|||||||
template<Ratio Ratio1, Ratio Ratio2>
|
template<Ratio Ratio1, Ratio Ratio2>
|
||||||
using common_ratio_t = typename common_ratio<Ratio1, Ratio2>::type;
|
using common_ratio_t = typename common_ratio<Ratio1, Ratio2>::type;
|
||||||
|
|
||||||
|
// upcastable
|
||||||
|
|
||||||
|
template<typename BaseType>
|
||||||
|
struct upcastable {
|
||||||
|
using base_type = BaseType;
|
||||||
|
};
|
||||||
|
|
||||||
// upcasting_traits
|
// upcasting_traits
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@@ -71,7 +71,7 @@ namespace units {
|
|||||||
struct exp_greater_equal : std::bool_constant<(E1::value >= E2::value)> {
|
struct exp_greater_equal : std::bool_constant<(E1::value >= E2::value)> {
|
||||||
};
|
};
|
||||||
|
|
||||||
// exp_invert
|
// exp_invert
|
||||||
|
|
||||||
template<Exponent E>
|
template<Exponent E>
|
||||||
struct exp_invert;
|
struct exp_invert;
|
||||||
@@ -87,9 +87,7 @@ namespace units {
|
|||||||
// dimension
|
// dimension
|
||||||
|
|
||||||
template<Exponent... Es>
|
template<Exponent... Es>
|
||||||
struct dimension {
|
struct dimension : upcastable<dimension<Es...>> {};
|
||||||
using base_type = dimension<Es...>;
|
|
||||||
};
|
|
||||||
|
|
||||||
// is_dimension
|
// is_dimension
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
@@ -29,8 +29,7 @@ namespace units {
|
|||||||
|
|
||||||
template<Dimension D, Ratio R>
|
template<Dimension D, Ratio R>
|
||||||
requires (R::num > 0)
|
requires (R::num > 0)
|
||||||
struct unit {
|
struct unit : upcastable<unit<D, R>> {
|
||||||
using base_type = unit<D, R>;
|
|
||||||
using dimension = D;
|
using dimension = D;
|
||||||
using ratio = R;
|
using ratio = R;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user