mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-04 12:54:25 +02:00
refactor: concept cleanup
This commit is contained in:
@@ -34,7 +34,11 @@ struct base_dimension;
|
||||
namespace detail {
|
||||
|
||||
template<basic_symbol_text Symbol>
|
||||
void to_base_base_dimension(const volatile base_dimension<Symbol>*);
|
||||
void to_base_specialization_of_base_dimension(const volatile base_dimension<Symbol>*);
|
||||
|
||||
template<typename T>
|
||||
inline constexpr bool is_derived_from_specialization_of_base_dimension =
|
||||
requires(T* t) { to_base_specialization_of_base_dimension(t); };
|
||||
|
||||
template<typename T>
|
||||
inline constexpr bool is_specialization_of_base_dimension = false;
|
||||
@@ -48,7 +52,8 @@ inline constexpr bool is_specialization_of_base_dimension<base_dimension<Symbol>
|
||||
* Satisfied by all dimension types derived from a specialization of `base_dimension`.
|
||||
*/
|
||||
template<typename T>
|
||||
concept BaseDimension = requires(T* t) { to_base_base_dimension(t); } && (!is_specialization_of_base_dimension<T>);
|
||||
concept BaseDimension =
|
||||
is_derived_from_specialization_of_base_dimension<T> && (!is_specialization_of_base_dimension<T>);
|
||||
|
||||
template<typename T>
|
||||
struct is_dimension_one : std::false_type {};
|
||||
|
@@ -37,6 +37,10 @@ namespace detail {
|
||||
template<auto R, typename Rep>
|
||||
void to_base_specialization_of_quantity(const volatile quantity<R, Rep>*);
|
||||
|
||||
template<typename T>
|
||||
inline constexpr bool is_derived_from_specialization_of_quantity =
|
||||
requires(T* t) { to_base_specialization_of_quantity(t); };
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/**
|
||||
@@ -45,7 +49,7 @@ void to_base_specialization_of_quantity(const volatile quantity<R, Rep>*);
|
||||
* Satisfied by all types being a either specialization or derived from `quantity`
|
||||
*/
|
||||
template<typename T>
|
||||
concept Quantity = requires(T* t) { detail::to_base_specialization_of_quantity(t); };
|
||||
concept Quantity = detail::is_derived_from_specialization_of_quantity<T>;
|
||||
|
||||
/**
|
||||
* @brief A concept matching all quantities with provided dimension or quantity spec
|
||||
|
@@ -81,7 +81,11 @@ template<auto R, auto PO, typename Rep>
|
||||
void to_base_specialization_of_quantity_point(const volatile quantity_point<R, PO, Rep>*);
|
||||
|
||||
template<typename T>
|
||||
requires requires(T* t) { detail::to_base_specialization_of_quantity_point(t); }
|
||||
inline constexpr bool is_derived_from_specialization_of_quantity_point =
|
||||
requires(T* t) { to_base_specialization_of_quantity_point(t); };
|
||||
|
||||
template<typename T>
|
||||
requires is_derived_from_specialization_of_quantity_point<T>
|
||||
inline constexpr bool is_quantity_point<T> = true;
|
||||
|
||||
} // namespace detail
|
||||
|
@@ -56,6 +56,10 @@ template<typename T, auto... Args>
|
||||
void to_base_specialization_of_quantity_spec(const volatile quantity_spec<T, Args...>*);
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
inline constexpr bool is_derived_from_specialization_of_quantity_spec =
|
||||
requires(T* t) { to_base_specialization_of_quantity_spec(t); };
|
||||
|
||||
#ifdef __cpp_explicit_this_parameter
|
||||
template<BaseDimension auto Dim, auto... Args>
|
||||
template<auto... Args>
|
||||
@@ -65,6 +69,10 @@ template<typename Self, BaseDimension auto Dim, auto... Args>
|
||||
void to_base_specialization_of_base_quantity_spec(const volatile quantity_spec<Self, Dim, Args...>*);
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
inline constexpr bool is_derived_from_specialization_of_base_quantity_spec =
|
||||
requires(T* t) { to_base_specialization_of_base_quantity_spec(t); };
|
||||
|
||||
template<typename T>
|
||||
inline constexpr bool is_specialization_of_quantity_spec = false;
|
||||
|
||||
@@ -82,7 +90,7 @@ inline constexpr bool is_specialization_of_quantity_spec<quantity_spec<T, Args..
|
||||
* Satisfied by all types that derive from `quantity_spec`.
|
||||
*/
|
||||
template<typename T>
|
||||
concept NamedQuantitySpec = requires(T* t) { to_base_specialization_of_quantity_spec(t); } &&
|
||||
concept NamedQuantitySpec = is_derived_from_specialization_of_quantity_spec<T> &&
|
||||
(!is_specialization_of_quantity_spec<T>)&&(!QuantityKindSpec<T>);
|
||||
|
||||
/**
|
||||
@@ -92,7 +100,7 @@ concept NamedQuantitySpec = requires(T* t) { to_base_specialization_of_quantity_
|
||||
* as a template parameter.
|
||||
*/
|
||||
template<typename T>
|
||||
concept BaseQuantitySpec = NamedQuantitySpec<T> && requires(T* t) { to_base_specialization_of_base_quantity_spec(t); };
|
||||
concept BaseQuantitySpec = NamedQuantitySpec<T> && is_derived_from_specialization_of_base_quantity_spec<T>;
|
||||
|
||||
template<typename T>
|
||||
struct is_dimensionless : std::false_type {};
|
||||
|
@@ -68,10 +68,11 @@ inline constexpr bool is_specialization_of_named_unit<named_unit<Symbol, Args...
|
||||
/**
|
||||
* @brief A concept matching all units with special names
|
||||
*
|
||||
* Satisfied by all unit types derived from the specialization of `named_unit` (but not constant units).
|
||||
* Satisfied by all unit types derived from the specialization of `named_unit`.
|
||||
*/
|
||||
template<typename T>
|
||||
concept NamedUnit = Unit<T> && detail::is_derived_from_specialization_of_named_unit<T>;
|
||||
concept NamedUnit =
|
||||
Unit<T> && detail::is_derived_from_specialization_of_named_unit<T> && (!detail::is_specialization_of_named_unit<T>);
|
||||
|
||||
} // namespace detail
|
||||
|
||||
|
Reference in New Issue
Block a user