mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-05 05:04:27 +02:00
refactor: *_instantation_of to *_specialization_of
This commit is contained in:
committed by
Mateusz Pusz
parent
65286b7a81
commit
46761ea2f7
14
src/include/units/bits/external/type_traits.h
vendored
14
src/include/units/bits/external/type_traits.h
vendored
@@ -57,25 +57,25 @@ inline constexpr bool is_same_v<T, T> = true;
|
||||
template<class T, class U>
|
||||
using is_same = std::bool_constant<is_same_v<T, U>>;
|
||||
|
||||
// is_instantiation_of
|
||||
// is_specialization_of
|
||||
namespace detail {
|
||||
|
||||
template<typename T, template<typename...> typename Type>
|
||||
inline constexpr bool is_instantiation_of_impl = false;
|
||||
inline constexpr bool is_specialization_of_impl = false;
|
||||
|
||||
template<typename... Params, template<typename...> typename Type>
|
||||
inline constexpr bool is_instantiation_of_impl<Type<Params...>, Type> = true;
|
||||
inline constexpr bool is_specialization_of_impl<Type<Params...>, Type> = true;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<typename T, template<typename...> typename Type>
|
||||
inline constexpr bool is_instantiation_of = detail::is_instantiation_of_impl<T, Type>;
|
||||
inline constexpr bool is_specialization_of = detail::is_specialization_of_impl<T, Type>;
|
||||
|
||||
// is_derived_from_instantiation_of
|
||||
// is_derived_from_specialization_of
|
||||
namespace detail {
|
||||
|
||||
template<template<typename...> typename Type>
|
||||
struct is_derived_from_instantiation_of_impl {
|
||||
struct is_derived_from_specialization_of_impl {
|
||||
template<typename... Params>
|
||||
static constexpr std::true_type check_base(const Type<Params...>&);
|
||||
static constexpr std::false_type check_base(...);
|
||||
@@ -84,6 +84,6 @@ struct is_derived_from_instantiation_of_impl {
|
||||
} // namespace detail
|
||||
|
||||
template<typename T, template<typename...> typename Type>
|
||||
inline constexpr bool is_derived_from_instantiation_of = decltype(detail::is_derived_from_instantiation_of_impl<Type>::check_base(std::declval<T>()))::value;
|
||||
inline constexpr bool is_derived_from_specialization_of = decltype(detail::is_derived_from_specialization_of_impl<Type>::check_base(std::declval<T>()))::value;
|
||||
|
||||
} // namespace units
|
||||
|
@@ -57,7 +57,7 @@ concept PrefixFamily = std::derived_from<T, prefix_family>;
|
||||
/**
|
||||
* @brief A concept matching a symbol prefix
|
||||
*
|
||||
* Satisfied by all instantiations of `prefix`.
|
||||
* Satisfied by all specializations of `prefix`.
|
||||
*/
|
||||
template<typename T>
|
||||
// concept Prefix = detail::is_prefix<T>;
|
||||
@@ -94,7 +94,7 @@ inline constexpr bool is_derived_from_scaled_unit = decltype(is_derived_from_sca
|
||||
/**
|
||||
* @brief A concept matching all unit types in the library
|
||||
*
|
||||
* Satisfied by all unit types derived from the instantiation of :class:`scaled_unit`.
|
||||
* Satisfied by all unit types derived from an specialization of :class:`scaled_unit`.
|
||||
*/
|
||||
template<typename T>
|
||||
concept Unit = detail::is_derived_from_scaled_unit<T>;
|
||||
@@ -119,7 +119,7 @@ inline constexpr bool is_derived_from_base_dimension = decltype(is_derived_from_
|
||||
/**
|
||||
* @brief A concept matching all base dimensions in the library.
|
||||
*
|
||||
* Satisfied by all dimension types derived from the instantiation of `base_dimension`.
|
||||
* Satisfied by all dimension types derived from an specialization of `base_dimension`.
|
||||
*/
|
||||
template<typename T>
|
||||
concept BaseDimension = detail::is_derived_from_base_dimension<T>;
|
||||
@@ -135,7 +135,7 @@ inline constexpr bool is_exp = false;
|
||||
/**
|
||||
* @brief A concept matching dimension's exponents.
|
||||
*
|
||||
* Satisfied by all instantiations of :class:`exp`.
|
||||
* Satisfied by all specializations of :class:`exp`.
|
||||
*/
|
||||
template<typename T>
|
||||
concept Exponent = detail::is_exp<T>;
|
||||
@@ -152,10 +152,10 @@ struct derived_dimension_base;
|
||||
/**
|
||||
* @brief A concept matching all derived dimensions in the library.
|
||||
*
|
||||
* Satisfied by all dimension types derived from the instantiation of `detail::derived_dimension_base`.
|
||||
* Satisfied by all dimension types derived from an specialization of `detail::derived_dimension_base`.
|
||||
*/
|
||||
template<typename T>
|
||||
concept DerivedDimension = is_derived_from_instantiation_of<T, detail::derived_dimension_base>;
|
||||
concept DerivedDimension = is_derived_from_specialization_of<T, detail::derived_dimension_base>;
|
||||
|
||||
// Dimension
|
||||
/**
|
||||
@@ -224,7 +224,7 @@ inline constexpr bool is_quantity_point = false;
|
||||
/**
|
||||
* @brief A concept matching all quantities in the library.
|
||||
*
|
||||
* Satisfied by all instantiations of :class:`quantity`.
|
||||
* Satisfied by all specializations of :class:`quantity`.
|
||||
*/
|
||||
template<typename T>
|
||||
concept Quantity = detail::is_quantity<T>;
|
||||
@@ -232,7 +232,7 @@ concept Quantity = detail::is_quantity<T>;
|
||||
/**
|
||||
* @brief A concept matching all quantity points in the library.
|
||||
*
|
||||
* Satisfied by all instantiations of :class:`quantity_point`.
|
||||
* Satisfied by all specializations of :class:`quantity_point`.
|
||||
*/
|
||||
template<typename T>
|
||||
concept QuantityPoint = detail::is_quantity_point<T>;
|
||||
|
@@ -30,10 +30,10 @@
|
||||
namespace units::physical {
|
||||
|
||||
template<typename Dim, template<typename...> typename DimTemplate>
|
||||
concept DimensionOf = Dimension<Dim> && is_derived_from_instantiation_of<Dim, DimTemplate>;
|
||||
concept DimensionOf = Dimension<Dim> && is_derived_from_specialization_of<Dim, DimTemplate>;
|
||||
|
||||
template<typename Q, template<typename...> typename DimTemplate>
|
||||
concept QuantityOf = Quantity<Q> && is_derived_from_instantiation_of<typename Q::dimension, DimTemplate>;
|
||||
concept QuantityOf = Quantity<Q> && is_derived_from_specialization_of<typename Q::dimension, DimTemplate>;
|
||||
|
||||
// ------------------------ base dimensions -----------------------------
|
||||
|
||||
|
@@ -379,10 +379,10 @@ template<Scalar ToRep, typename D, typename U, typename Rep>
|
||||
*/
|
||||
template<typename CastSpec, typename D, typename U, typename Rep>
|
||||
[[nodiscard]] constexpr auto quantity_point_cast(const quantity_point<D, U, Rep>& qp)
|
||||
requires is_instantiation_of<CastSpec, quantity_point> ||
|
||||
requires is_specialization_of<CastSpec, quantity_point> ||
|
||||
requires(quantity<D, U, Rep> q) { quantity_cast<CastSpec>(q); }
|
||||
{
|
||||
if constexpr (is_instantiation_of<CastSpec, quantity_point>)
|
||||
if constexpr (is_specialization_of<CastSpec, quantity_point>)
|
||||
return quantity_point(quantity_cast<typename CastSpec::quantity_type>(qp.relative()));
|
||||
else
|
||||
return quantity_point(quantity_cast<CastSpec>(qp.relative()));
|
||||
|
Reference in New Issue
Block a user