mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-30 18:37:15 +02:00
base_dimension is provided as a const& to the exp type
This commit is contained in:
@ -27,23 +27,42 @@
|
|||||||
|
|
||||||
namespace std::experimental::units {
|
namespace std::experimental::units {
|
||||||
|
|
||||||
// dim_id
|
struct base_dimension {
|
||||||
|
const char* name;
|
||||||
|
};
|
||||||
|
|
||||||
template<int UniqueValue>
|
constexpr bool operator==(const base_dimension& lhs, const base_dimension& rhs)
|
||||||
using dim_id = std::integral_constant<int, UniqueValue>;
|
{
|
||||||
|
const char* p1 = lhs.name;
|
||||||
|
const char* p2 = rhs.name;
|
||||||
|
for(; (*p1 != '\0') && (*p2 != '\0'); ++p1, (void)++p2) {
|
||||||
|
if(*p1 != *p2) return false;
|
||||||
|
}
|
||||||
|
return *p1 == *p2;
|
||||||
|
}
|
||||||
|
|
||||||
// dim_id_less
|
constexpr bool operator<(const base_dimension& lhs, const base_dimension& rhs)
|
||||||
|
{
|
||||||
|
const char* p1 = lhs.name;
|
||||||
|
const char* p2 = rhs.name;
|
||||||
|
for(; (*p1 != '\0') && (*p2 != '\0'); ++p1, (void)++p2) {
|
||||||
|
if(*p1 < *p2) return true;
|
||||||
|
if(*p2 < *p1) return false;
|
||||||
|
}
|
||||||
|
return (*p1 == '\0') && (*p2 != '\0');
|
||||||
|
}
|
||||||
|
|
||||||
template<typename D1, typename D2>
|
// base_dimension_less
|
||||||
struct dim_id_less : std::bool_constant<D1::value < D2::value> {
|
|
||||||
|
template<const base_dimension& D1, const base_dimension& D2>
|
||||||
|
struct base_dimension_less : std::bool_constant<D1 < D2> {
|
||||||
};
|
};
|
||||||
|
|
||||||
// exp
|
// exp
|
||||||
|
|
||||||
template<typename BaseDimension, int Value> // todo: to be replaced with fixed_string when supported by the compilers
|
template<const base_dimension& BaseDimension, int Value>
|
||||||
// template<fixed_string BaseDimension, int Value>
|
|
||||||
struct exp {
|
struct exp {
|
||||||
using dimension = BaseDimension;
|
static constexpr const base_dimension& dimension = BaseDimension;
|
||||||
static constexpr int value = Value;
|
static constexpr int value = Value;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -52,8 +71,8 @@ namespace std::experimental::units {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
inline constexpr bool is_exp = false;
|
inline constexpr bool is_exp = false;
|
||||||
|
|
||||||
template<typename BaseDim, int Value>
|
template<const base_dimension& BaseDimension, int Value>
|
||||||
inline constexpr bool is_exp<exp<BaseDim, Value>> = true;
|
inline constexpr bool is_exp<exp<BaseDimension, Value>> = true;
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@ -62,7 +81,7 @@ namespace std::experimental::units {
|
|||||||
// exp_dim_id_less
|
// exp_dim_id_less
|
||||||
|
|
||||||
template<Exponent E1, Exponent E2>
|
template<Exponent E1, Exponent E2>
|
||||||
struct exp_dim_id_less : dim_id_less<typename E1::dimension, typename E2::dimension> {
|
struct exp_less : base_dimension_less<E1::dimension, E2::dimension> {
|
||||||
};
|
};
|
||||||
|
|
||||||
// exp_invert
|
// exp_invert
|
||||||
@ -70,7 +89,7 @@ namespace std::experimental::units {
|
|||||||
template<Exponent E>
|
template<Exponent E>
|
||||||
struct exp_invert;
|
struct exp_invert;
|
||||||
|
|
||||||
template<typename BaseDimension, int Value>
|
template<const base_dimension& BaseDimension, int Value>
|
||||||
struct exp_invert<exp<BaseDimension, Value>> {
|
struct exp_invert<exp<BaseDimension, Value>> {
|
||||||
using type = exp<BaseDimension, -Value>;
|
using type = exp<BaseDimension, -Value>;
|
||||||
};
|
};
|
||||||
@ -138,7 +157,7 @@ namespace std::experimental::units {
|
|||||||
using type = conditional<std::is_same_v<rest, dimension<>>, dimension<E1>, type_list_push_front<rest, E1>>;
|
using type = conditional<std::is_same_v<rest, dimension<>>, dimension<E1>, type_list_push_front<rest, E1>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename D, int V1, int V2, typename... ERest>
|
template<const base_dimension& D, int V1, int V2, typename... ERest>
|
||||||
struct dim_consolidate<dimension<exp<D, V1>, exp<D, V2>, ERest...>> {
|
struct dim_consolidate<dimension<exp<D, V1>, exp<D, V2>, ERest...>> {
|
||||||
using type = conditional<V1 + V2 == 0, dim_consolidate_t<dimension<ERest...>>,
|
using type = conditional<V1 + V2 == 0, dim_consolidate_t<dimension<ERest...>>,
|
||||||
dim_consolidate_t<dimension<exp<D, V1 + V2>, ERest...>>>;
|
dim_consolidate_t<dimension<exp<D, V1 + V2>, ERest...>>>;
|
||||||
@ -148,7 +167,7 @@ namespace std::experimental::units {
|
|||||||
|
|
||||||
template<Exponent... Es>
|
template<Exponent... Es>
|
||||||
struct make_dimension {
|
struct make_dimension {
|
||||||
using type = detail::dim_consolidate_t<type_list_sort<dimension<Es...>, exp_dim_id_less>>;
|
using type = detail::dim_consolidate_t<type_list_sort<dimension<Es...>, exp_less>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<Exponent... Es>
|
template<Exponent... Es>
|
||||||
@ -156,7 +175,7 @@ namespace std::experimental::units {
|
|||||||
|
|
||||||
template<Dimension D1, Dimension D2>
|
template<Dimension D1, Dimension D2>
|
||||||
struct merge_dimension {
|
struct merge_dimension {
|
||||||
using type = detail::dim_consolidate_t<type_list_merge_sorted<D1, D2, exp_dim_id_less>>;
|
using type = detail::dim_consolidate_t<type_list_merge_sorted<D1, D2, exp_less>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<Dimension D1, Dimension D2>
|
template<Dimension D1, Dimension D2>
|
||||||
|
@ -26,14 +26,12 @@
|
|||||||
|
|
||||||
namespace std::experimental::units {
|
namespace std::experimental::units {
|
||||||
|
|
||||||
// todo: to be replaced with fixed_string when supported by the compilers
|
inline constexpr base_dimension base_dim_length{"length"};
|
||||||
|
inline constexpr base_dimension base_dim_mass{"mass"};
|
||||||
struct base_dim_length : dim_id<0> {};
|
inline constexpr base_dimension base_dim_time{"time"};
|
||||||
struct base_dim_mass : dim_id<1> {};
|
inline constexpr base_dimension base_dim_current{"current"};
|
||||||
struct base_dim_time : dim_id<2> {};
|
inline constexpr base_dimension base_dim_temperature{"temperature"};
|
||||||
struct base_dim_current : dim_id<3> {};
|
inline constexpr base_dimension base_dim_substance{"substance"};
|
||||||
struct base_dim_temperature : dim_id<4> {};
|
inline constexpr base_dimension base_dim_luminous_intensity{"luminous intensity"};
|
||||||
struct base_dim_substance : dim_id<5> {};
|
|
||||||
struct base_dim_luminous_intensity : dim_id<6> {};
|
|
||||||
|
|
||||||
} // namespace std::experimental::units
|
} // namespace std::experimental::units
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <units/base_dimensions.h>
|
#include <units/dimensions/base_dimensions.h>
|
||||||
#include <units/dimensions/electric_charge.h>
|
#include <units/dimensions/electric_charge.h>
|
||||||
#include <units/dimensions/voltage.h>
|
#include <units/dimensions/voltage.h>
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <units/base_dimensions.h>
|
#include <units/dimensions/base_dimensions.h>
|
||||||
#include <units/quantity.h>
|
#include <units/quantity.h>
|
||||||
|
|
||||||
namespace std::experimental::units {
|
namespace std::experimental::units {
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <units/base_dimensions.h>
|
#include <units/dimensions/base_dimensions.h>
|
||||||
#include <units/dimensions/time.h>
|
#include <units/dimensions/time.h>
|
||||||
#include <units/dimensions/current.h>
|
#include <units/dimensions/current.h>
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <units/base_dimensions.h>
|
#include <units/dimensions/base_dimensions.h>
|
||||||
#include <units/dimensions/force.h>
|
#include <units/dimensions/force.h>
|
||||||
#include <units/dimensions/pressure.h>
|
#include <units/dimensions/pressure.h>
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <units/base_dimensions.h>
|
#include <units/dimensions/base_dimensions.h>
|
||||||
#include <units/dimensions/mass.h>
|
#include <units/dimensions/mass.h>
|
||||||
#include <units/dimensions/length.h>
|
#include <units/dimensions/length.h>
|
||||||
#include <units/dimensions/time.h>
|
#include <units/dimensions/time.h>
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <units/base_dimensions.h>
|
#include <units/dimensions/base_dimensions.h>
|
||||||
#include <units/dimensions/time.h>
|
#include <units/dimensions/time.h>
|
||||||
|
|
||||||
namespace std::experimental::units {
|
namespace std::experimental::units {
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <units/base_dimensions.h>
|
#include <units/dimensions/base_dimensions.h>
|
||||||
#include <units/quantity.h>
|
#include <units/quantity.h>
|
||||||
|
|
||||||
namespace std::experimental::units {
|
namespace std::experimental::units {
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <units/base_dimensions.h>
|
#include <units/dimensions/base_dimensions.h>
|
||||||
#include <units/quantity.h>
|
#include <units/quantity.h>
|
||||||
|
|
||||||
namespace std::experimental::units {
|
namespace std::experimental::units {
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <units/base_dimensions.h>
|
#include <units/dimensions/base_dimensions.h>
|
||||||
#include <units/quantity.h>
|
#include <units/quantity.h>
|
||||||
|
|
||||||
namespace std::experimental::units {
|
namespace std::experimental::units {
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <units/base_dimensions.h>
|
#include <units/dimensions/base_dimensions.h>
|
||||||
#include <units/dimensions/energy.h>
|
#include <units/dimensions/energy.h>
|
||||||
|
|
||||||
namespace std::experimental::units {
|
namespace std::experimental::units {
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <units/base_dimensions.h>
|
#include <units/dimensions/base_dimensions.h>
|
||||||
#include <units/dimensions/force.h>
|
#include <units/dimensions/force.h>
|
||||||
|
|
||||||
namespace std::experimental::units {
|
namespace std::experimental::units {
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <units/base_dimensions.h>
|
#include <units/dimensions/base_dimensions.h>
|
||||||
#include <units/quantity.h>
|
#include <units/quantity.h>
|
||||||
|
|
||||||
namespace std::experimental::units {
|
namespace std::experimental::units {
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <units/base_dimensions.h>
|
#include <units/dimensions/base_dimensions.h>
|
||||||
#include <units/quantity.h>
|
#include <units/quantity.h>
|
||||||
|
|
||||||
namespace std::experimental::units {
|
namespace std::experimental::units {
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <units/base_dimensions.h>
|
#include <units/dimensions/base_dimensions.h>
|
||||||
#include <units/quantity.h>
|
#include <units/quantity.h>
|
||||||
|
|
||||||
namespace std::experimental::units {
|
namespace std::experimental::units {
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <units/base_dimensions.h>
|
#include <units/dimensions/base_dimensions.h>
|
||||||
#include <units/dimensions/power.h>
|
#include <units/dimensions/power.h>
|
||||||
#include <units/dimensions/current.h>
|
#include <units/dimensions/current.h>
|
||||||
#include <units/dimensions/energy.h>
|
#include <units/dimensions/energy.h>
|
||||||
|
@ -63,18 +63,18 @@ namespace std::experimental::units {
|
|||||||
template<typename E, typename... Rest>
|
template<typename E, typename... Rest>
|
||||||
struct get_unit_base_dim<dimension<E, Rest...>> {
|
struct get_unit_base_dim<dimension<E, Rest...>> {
|
||||||
static_assert(sizeof...(Rest) == 0, "Base unit expected");
|
static_assert(sizeof...(Rest) == 0, "Base unit expected");
|
||||||
using dimension = E::dimension;
|
static constexpr const base_dimension& dimension = E::dimension;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename BaseDimension, typename... Us>
|
template<const base_dimension& BaseDimension, typename... Us>
|
||||||
struct get_ratio {
|
struct get_ratio {
|
||||||
using ratio = ::std::experimental::units::ratio<1>;
|
using ratio = ::std::experimental::units::ratio<1>;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename BaseDimension, typename U, typename... Rest>
|
template<const base_dimension& BaseDimension, typename U, typename... Rest>
|
||||||
struct get_ratio<BaseDimension, U, Rest...> {
|
struct get_ratio<BaseDimension, U, Rest...> {
|
||||||
using unit_base_dim = get_unit_base_dim<typename U::dimension::base_type>::dimension;
|
static constexpr const base_dimension& unit_base_dim = get_unit_base_dim<typename U::dimension::base_type>::dimension;
|
||||||
using ratio = conditional<unit_base_dim::value == BaseDimension::value, typename U::ratio,
|
using ratio = conditional<&unit_base_dim == &BaseDimension, typename U::ratio,
|
||||||
typename get_ratio<BaseDimension, Rest...>::ratio>;
|
typename get_ratio<BaseDimension, Rest...>::ratio>;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ namespace std::experimental::units {
|
|||||||
template<typename E, typename... Rest, typename... Us>
|
template<typename E, typename... Rest, typename... Us>
|
||||||
struct derived_ratio<dimension<E, Rest...>, Us...> {
|
struct derived_ratio<dimension<E, Rest...>, Us...> {
|
||||||
using rest_ratio = derived_ratio<dimension<Rest...>, Us...>::ratio;
|
using rest_ratio = derived_ratio<dimension<Rest...>, Us...>::ratio;
|
||||||
using e_ratio = get_ratio<typename E::dimension, Us...>::ratio;
|
using e_ratio = get_ratio<E::dimension, Us...>::ratio;
|
||||||
using ratio = ratio_op<rest_ratio, E::value, e_ratio>::ratio;
|
using ratio = ratio_op<rest_ratio, E::value, e_ratio>::ratio;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -27,46 +27,48 @@ using namespace std::experimental::units;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
template<int Id, int Value>
|
inline constexpr base_dimension d0{"d0"};
|
||||||
using e = exp<dim_id<Id>, Value>;
|
inline constexpr base_dimension d1{"d1"};
|
||||||
|
inline constexpr base_dimension d2{"d2"};
|
||||||
|
inline constexpr base_dimension d3{"d3"};
|
||||||
|
|
||||||
// exp_invert
|
// exp_invert
|
||||||
|
|
||||||
static_assert(std::is_same_v<exp_invert_t<e<0, 1>>, e<0, -1>>);
|
static_assert(std::is_same_v<exp_invert_t<exp<d0, 1>>, exp<d0, -1>>);
|
||||||
static_assert(std::is_same_v<exp_invert_t<e<1, -1>>, e<1, 1>>);
|
static_assert(std::is_same_v<exp_invert_t<exp<d1, -1>>, exp<d1, 1>>);
|
||||||
|
|
||||||
// make_dimension
|
// make_dimension
|
||||||
|
|
||||||
static_assert(std::is_same_v<make_dimension_t<e<0, 1>>, dimension<e<0, 1>>>);
|
static_assert(std::is_same_v<make_dimension_t<exp<d0, 1>>, dimension<exp<d0, 1>>>);
|
||||||
static_assert(std::is_same_v<make_dimension_t<e<0, 1>, e<1, 1>>, dimension<e<0, 1>, e<1, 1>>>);
|
static_assert(std::is_same_v<make_dimension_t<exp<d0, 1>, exp<d1, 1>>, dimension<exp<d0, 1>, exp<d1, 1>>>);
|
||||||
static_assert(std::is_same_v<make_dimension_t<e<1, 1>, e<0, 1>>, dimension<e<0, 1>, e<1, 1>>>);
|
static_assert(std::is_same_v<make_dimension_t<exp<d1, 1>, exp<d0, 1>>, dimension<exp<d0, 1>, exp<d1, 1>>>);
|
||||||
static_assert(std::is_same_v<make_dimension_t<e<1, 1>, e<1, 1>>, dimension<e<1, 2>>>);
|
static_assert(std::is_same_v<make_dimension_t<exp<d1, 1>, exp<d1, 1>>, dimension<exp<d1, 2>>>);
|
||||||
static_assert(std::is_same_v<make_dimension_t<e<1, 1>, e<1, -1>>, dimension<>>);
|
static_assert(std::is_same_v<make_dimension_t<exp<d1, 1>, exp<d1, -1>>, dimension<>>);
|
||||||
|
|
||||||
static_assert(std::is_same_v<make_dimension_t<e<0, 1>, e<1, 1>, e<0, 1>, e<1, 1>>, dimension<e<0, 2>, e<1, 2>>>);
|
static_assert(std::is_same_v<make_dimension_t<exp<d0, 1>, exp<d1, 1>, exp<d0, 1>, exp<d1, 1>>, dimension<exp<d0, 2>, exp<d1, 2>>>);
|
||||||
static_assert(
|
static_assert(
|
||||||
std::is_same_v<make_dimension_t<e<0, -1>, e<1, -1>, e<0, -1>, e<1, -1>>, dimension<e<0, -2>, e<1, -2>>>);
|
std::is_same_v<make_dimension_t<exp<d0, -1>, exp<d1, -1>, exp<d0, -1>, exp<d1, -1>>, dimension<exp<d0, -2>, exp<d1, -2>>>);
|
||||||
|
|
||||||
static_assert(std::is_same_v<make_dimension_t<e<0, 1>, e<1, 1>, e<1, -1>>, dimension<e<0, 1>>>);
|
static_assert(std::is_same_v<make_dimension_t<exp<d0, 1>, exp<d1, 1>, exp<d1, -1>>, dimension<exp<d0, 1>>>);
|
||||||
static_assert(std::is_same_v<make_dimension_t<e<0, 1>, e<0, -1>, e<1, 1>>, dimension<e<1, 1>>>);
|
static_assert(std::is_same_v<make_dimension_t<exp<d0, 1>, exp<d0, -1>, exp<d1, 1>>, dimension<exp<d1, 1>>>);
|
||||||
static_assert(std::is_same_v<make_dimension_t<e<0, 1>, e<1, 1>, e<0, -1>>, dimension<e<1, 1>>>);
|
static_assert(std::is_same_v<make_dimension_t<exp<d0, 1>, exp<d1, 1>, exp<d0, -1>>, dimension<exp<d1, 1>>>);
|
||||||
static_assert(std::is_same_v<make_dimension_t<e<0, 1>, e<1, 1>, e<0, -1>, e<1, -1>>, dimension<>>);
|
static_assert(std::is_same_v<make_dimension_t<exp<d0, 1>, exp<d1, 1>, exp<d0, -1>, exp<d1, -1>>, dimension<>>);
|
||||||
|
|
||||||
// dimension_multiply
|
// dimension_multiply
|
||||||
|
|
||||||
static_assert(
|
static_assert(
|
||||||
std::is_same_v<dimension_multiply_t<dimension<e<0, 1>>, dimension<e<1, 1>>>, dimension<e<0, 1>, e<1, 1>>>);
|
std::is_same_v<dimension_multiply_t<dimension<exp<d0, 1>>, dimension<exp<d1, 1>>>, dimension<exp<d0, 1>, exp<d1, 1>>>);
|
||||||
static_assert(std::is_same_v<dimension_multiply_t<dimension<e<0, 1>, e<1, 1>, e<2, 1>>, dimension<e<3, 1>>>,
|
static_assert(std::is_same_v<dimension_multiply_t<dimension<exp<d0, 1>, exp<d1, 1>, exp<d2, 1>>, dimension<exp<d3, 1>>>,
|
||||||
dimension<e<0, 1>, e<1, 1>, e<2, 1>, e<3, 1>>>);
|
dimension<exp<d0, 1>, exp<d1, 1>, exp<d2, 1>, exp<d3, 1>>>);
|
||||||
static_assert(std::is_same_v<dimension_multiply_t<dimension<e<0, 1>, e<1, 1>, e<2, 1>>, dimension<e<1, 1>>>,
|
static_assert(std::is_same_v<dimension_multiply_t<dimension<exp<d0, 1>, exp<d1, 1>, exp<d2, 1>>, dimension<exp<d1, 1>>>,
|
||||||
dimension<e<0, 1>, e<1, 2>, e<2, 1>>>);
|
dimension<exp<d0, 1>, exp<d1, 2>, exp<d2, 1>>>);
|
||||||
static_assert(std::is_same_v<dimension_multiply_t<dimension<e<0, 1>, e<1, 1>, e<2, 1>>, dimension<e<1, -1>>>,
|
static_assert(std::is_same_v<dimension_multiply_t<dimension<exp<d0, 1>, exp<d1, 1>, exp<d2, 1>>, dimension<exp<d1, -1>>>,
|
||||||
dimension<e<0, 1>, e<2, 1>>>);
|
dimension<exp<d0, 1>, exp<d2, 1>>>);
|
||||||
|
|
||||||
// dimension_divide
|
// dimension_divide
|
||||||
|
|
||||||
static_assert(
|
static_assert(
|
||||||
std::is_same_v<dimension_divide_t<dimension<e<0, 1>>, dimension<e<1, 1>>>, dimension<e<0, 1>, e<1, -1>>>);
|
std::is_same_v<dimension_divide_t<dimension<exp<d0, 1>>, dimension<exp<d1, 1>>>, dimension<exp<d0, 1>, exp<d1, -1>>>);
|
||||||
static_assert(std::is_same_v<dimension_divide_t<dimension<e<0, 1>>, dimension<e<0, 1>>>, dimension<>>);
|
static_assert(std::is_same_v<dimension_divide_t<dimension<exp<d0, 1>>, dimension<exp<d0, 1>>>, dimension<>>);
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -82,41 +82,21 @@ namespace {
|
|||||||
std::is_same_v<type_list_split_half<type_list<int, long, double, float>>::second_list, type_list<double, float>>);
|
std::is_same_v<type_list_split_half<type_list<int, long, double, float>>::second_list, type_list<double, float>>);
|
||||||
|
|
||||||
// type_list_merge_sorted
|
// type_list_merge_sorted
|
||||||
|
inline constexpr base_dimension d0{"d0"};
|
||||||
|
inline constexpr base_dimension d1{"d1"};
|
||||||
|
|
||||||
static_assert(std::is_same_v<type_list_merge_sorted<type_list<dim_id<0>>, type_list<dim_id<1>>, dim_id_less>,
|
static_assert(std::is_same_v<type_list_merge_sorted<type_list<exp<d0, 1>>, type_list<exp<d1, 1>>, exp_less>,
|
||||||
type_list<dim_id<0>, dim_id<1>>>);
|
type_list<exp<d0, 1>, exp<d1, 1>>>);
|
||||||
static_assert(std::is_same_v<type_list_merge_sorted<type_list<dim_id<1>>, type_list<dim_id<0>>, dim_id_less>,
|
static_assert(std::is_same_v<type_list_merge_sorted<type_list<exp<d1, 1>>, type_list<exp<d0, 1>>, exp_less>,
|
||||||
type_list<dim_id<0>, dim_id<1>>>);
|
type_list<exp<d0, 1>, exp<d1, 1>>>);
|
||||||
|
|
||||||
static_assert(std::is_same_v<type_list_merge_sorted<type_list<dim_id<27>, dim_id<38>>,
|
|
||||||
type_list<dim_id<3>, dim_id<43>>, dim_id_less>,
|
|
||||||
type_list<dim_id<3>, dim_id<27>, dim_id<38>, dim_id<43>>>);
|
|
||||||
static_assert(
|
|
||||||
std::is_same_v<type_list_merge_sorted<type_list<dim_id<9>, dim_id<82>>, type_list<dim_id<10>>, dim_id_less>,
|
|
||||||
type_list<dim_id<9>, dim_id<10>, dim_id<82>>>);
|
|
||||||
|
|
||||||
// type_list_sort
|
// type_list_sort
|
||||||
|
|
||||||
template<TypeList List>
|
template<TypeList List>
|
||||||
using dim_sort_t = type_list_sort<List, dim_id_less>;
|
using exp_sort_t = type_list_sort<List, exp_less>;
|
||||||
|
|
||||||
static_assert(std::is_same_v<dim_sort_t<type_list<dim_id<0>>>, type_list<dim_id<0>>>);
|
static_assert(std::is_same_v<exp_sort_t<dimension<exp<d0, 1>>>, dimension<exp<d0, 1>>>);
|
||||||
static_assert(std::is_same_v<dim_sort_t<type_list<dim_id<0>, dim_id<1>>>, type_list<dim_id<0>, dim_id<1>>>);
|
static_assert(std::is_same_v<exp_sort_t<dimension<exp<d0, 1>, exp<d1, -1>>>, dimension<exp<d0, 1>, exp<d1, -1>>>);
|
||||||
static_assert(std::is_same_v<dim_sort_t<type_list<dim_id<1>, dim_id<0>>>, type_list<dim_id<0>, dim_id<1>>>);
|
static_assert(std::is_same_v<exp_sort_t<dimension<exp<d1, 1>, exp<d0, -1>>>, dimension<exp<d0, -1>, exp<d1, 1>>>);
|
||||||
static_assert(std::is_same_v<
|
|
||||||
dim_sort_t<type_list<dim_id<38>, dim_id<27>, dim_id<43>, dim_id<3>, dim_id<9>, dim_id<82>, dim_id<10>>>,
|
|
||||||
type_list<dim_id<3>, dim_id<9>, dim_id<10>, dim_id<27>, dim_id<38>, dim_id<43>, dim_id<82>>>);
|
|
||||||
|
|
||||||
// exp_dim_id_less
|
|
||||||
|
|
||||||
template<int Id, int Value>
|
|
||||||
using e = exp<dim_id<Id>, Value>;
|
|
||||||
|
|
||||||
template<TypeList List>
|
|
||||||
using exp_sort_t = type_list_sort<List, exp_dim_id_less>;
|
|
||||||
|
|
||||||
static_assert(std::is_same_v<exp_sort_t<dimension<e<0, 1>>>, dimension<e<0, 1>>>);
|
|
||||||
static_assert(std::is_same_v<exp_sort_t<dimension<e<0, 1>, e<1, -1>>>, dimension<e<0, 1>, e<1, -1>>>);
|
|
||||||
static_assert(std::is_same_v<exp_sort_t<dimension<e<1, 1>, e<0, -1>>>, dimension<e<0, -1>, e<1, 1>>>);
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
Reference in New Issue
Block a user