mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-30 02:17:16 +02:00
Double sorting of exponents removed
This commit is contained in:
@ -179,17 +179,6 @@ contained base dimensions. Beside providing ordering to base dimensions it also
|
||||
- aggregate two arguments of the same base dimension but different exponents
|
||||
- eliminate two arguments of the same base dimension and with opposite equal exponents
|
||||
|
||||
Additionally, it would be good if the final type produced by `make_dimension_t` would be easy to
|
||||
understand for the user. For example we may decide to order base dimensions with decreasing order of
|
||||
their exponents. That is why second sorting of a type list may be required. For example:
|
||||
|
||||
```cpp
|
||||
template<Exponent... Es>
|
||||
struct make_dimension {
|
||||
using type = mp::type_list_sort_t<detail::dim_consolidate_t<mp::type_list_sort_t<dimension<Es...>, exp_dim_id_less>>, exp_greater_equal>;
|
||||
};
|
||||
```
|
||||
|
||||
|
||||
#### `merge_dimension`
|
||||
|
||||
@ -218,7 +207,7 @@ Example implementation of `merge_dimension` may look like:
|
||||
```cpp
|
||||
template<Dimension D1, Dimension D2>
|
||||
struct merge_dimension {
|
||||
using type = mp::type_list_sort_t<detail::dim_consolidate_t<mp::type_list_merge_sorted_t<D1, D2, exp_dim_id_less>>, exp_greater_equal>;
|
||||
using type = detail::dim_consolidate_t<mp::type_list_merge_sorted_t<D1, D2, exp_dim_id_less>>;
|
||||
};
|
||||
```
|
||||
|
||||
|
@ -65,12 +65,6 @@ namespace units {
|
||||
struct exp_dim_id_less : dim_id_less<typename E1::dimension, typename E2::dimension> {
|
||||
};
|
||||
|
||||
// exp_dim_id_less
|
||||
|
||||
template<Exponent E1, Exponent E2>
|
||||
struct exp_greater_equal : std::bool_constant<(E1::value >= E2::value)> {
|
||||
};
|
||||
|
||||
// exp_invert
|
||||
|
||||
template<Exponent E>
|
||||
@ -154,7 +148,7 @@ namespace units {
|
||||
|
||||
template<Exponent... Es>
|
||||
struct make_dimension {
|
||||
using type = type_list_sort<detail::dim_consolidate_t<type_list_sort<dimension<Es...>, exp_dim_id_less>>, exp_greater_equal>;
|
||||
using type = detail::dim_consolidate_t<type_list_sort<dimension<Es...>, exp_dim_id_less>>;
|
||||
};
|
||||
|
||||
template<Exponent... Es>
|
||||
@ -162,7 +156,7 @@ namespace units {
|
||||
|
||||
template<Dimension D1, Dimension D2>
|
||||
struct merge_dimension {
|
||||
using type = type_list_sort<detail::dim_consolidate_t<type_list_merge_sorted<D1, D2, exp_dim_id_less>>, exp_greater_equal>;
|
||||
using type = detail::dim_consolidate_t<type_list_merge_sorted<D1, D2, exp_dim_id_less>>;
|
||||
};
|
||||
|
||||
template<Dimension D1, Dimension D2>
|
||||
|
@ -59,7 +59,7 @@ namespace {
|
||||
static_assert(std::is_same_v<dimension_multiply_t<dimension<e<0, 1>, e<1, 1>, e<2, 1>>, dimension<e<3, 1>>>,
|
||||
dimension<e<0, 1>, e<1, 1>, e<2, 1>, e<3, 1>>>);
|
||||
static_assert(std::is_same_v<dimension_multiply_t<dimension<e<0, 1>, e<1, 1>, e<2, 1>>, dimension<e<1, 1>>>,
|
||||
dimension<e<1, 2>, e<0, 1>, e<2, 1>>>);
|
||||
dimension<e<0, 1>, e<1, 2>, e<2, 1>>>);
|
||||
static_assert(std::is_same_v<dimension_multiply_t<dimension<e<0, 1>, e<1, 1>, e<2, 1>>, dimension<e<1, -1>>>,
|
||||
dimension<e<0, 1>, e<2, 1>>>);
|
||||
|
||||
|
Reference in New Issue
Block a user