mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-01 03:14:29 +02:00
refactor: kind_of_
refactored to take a type to improve error messages
This commit is contained in:
@@ -34,7 +34,7 @@ template<typename, auto...>
|
||||
#endif
|
||||
struct quantity_spec;
|
||||
|
||||
template<auto Q>
|
||||
template<typename Q>
|
||||
struct kind_of_;
|
||||
|
||||
namespace detail {
|
||||
@@ -42,7 +42,7 @@ namespace detail {
|
||||
template<typename T>
|
||||
inline constexpr bool is_specialization_of_kind_of = false;
|
||||
|
||||
template<auto Q>
|
||||
template<typename Q>
|
||||
inline constexpr bool is_specialization_of_kind_of<kind_of_<Q>> = true;
|
||||
|
||||
template<typename T>
|
||||
|
@@ -450,30 +450,28 @@ template<QuantitySpec Q>
|
||||
} // namespace detail
|
||||
|
||||
#ifdef __cpp_explicit_this_parameter
|
||||
template<auto Q>
|
||||
requires(detail::QuantitySpecWithNoSpecifiers<std::remove_const_t<decltype(Q)>>) &&
|
||||
(detail::get_kind_tree_root(Q) == Q)
|
||||
struct kind_of_<Q> : std::remove_const_t<decltype(Q)> {
|
||||
static constexpr auto _quantity_spec_ = Q;
|
||||
template<typename Q>
|
||||
requires detail::QuantitySpecWithNoSpecifiers<Q> && (detail::get_kind_tree_root(Q{}) == Q{})
|
||||
struct kind_of_<Q> : Q {
|
||||
static constexpr auto _quantity_spec_ = Q{};
|
||||
};
|
||||
#else
|
||||
|
||||
#if MP_UNITS_COMP_CLANG
|
||||
template<auto Q>
|
||||
requires detail::QuantitySpecWithNoSpecifiers<std::remove_cvref_t<decltype(Q)>> &&
|
||||
(detail::get_kind_tree_root(Q) == Q)
|
||||
template<typename Q>
|
||||
requires detail::QuantitySpecWithNoSpecifiers<Q> && (detail::get_kind_tree_root(Q{}) == Q{})
|
||||
#else
|
||||
template<detail::QuantitySpecWithNoSpecifiers auto Q>
|
||||
requires(detail::get_kind_tree_root(Q) == Q)
|
||||
template<detail::QuantitySpecWithNoSpecifiers Q>
|
||||
requires(detail::get_kind_tree_root(Q{}) == Q{})
|
||||
#endif
|
||||
struct kind_of_<Q> : quantity_spec<kind_of_<Q>, Q> {
|
||||
static constexpr auto _quantity_spec_ = Q;
|
||||
struct kind_of_<Q> : quantity_spec<kind_of_<Q>, Q{}> {
|
||||
static constexpr auto _quantity_spec_ = Q{};
|
||||
};
|
||||
#endif
|
||||
|
||||
template<detail::QuantitySpecWithNoSpecifiers auto Q>
|
||||
requires(detail::get_kind_tree_root(Q) == Q)
|
||||
inline constexpr kind_of_<Q> kind_of;
|
||||
inline constexpr kind_of_<std::remove_const_t<decltype(Q)>> kind_of;
|
||||
|
||||
namespace detail {
|
||||
|
||||
@@ -601,10 +599,10 @@ template<QuantitySpec Q, int... Ints>
|
||||
return get_complexity(Q{});
|
||||
}
|
||||
|
||||
template<auto Q>
|
||||
template<typename Q>
|
||||
[[nodiscard]] consteval int get_complexity(kind_of_<Q>)
|
||||
{
|
||||
return get_complexity(Q);
|
||||
return get_complexity(Q{});
|
||||
}
|
||||
|
||||
template<QuantitySpec Q>
|
||||
|
@@ -111,10 +111,10 @@ static_assert(detail::NamedQuantitySpec<dimensionless_>);
|
||||
static_assert(!detail::IntermediateDerivedQuantitySpec<dimensionless_>);
|
||||
static_assert(!detail::QuantityKindSpec<dimensionless_>);
|
||||
|
||||
static_assert(QuantitySpec<kind_of_<length>>);
|
||||
static_assert(!detail::NamedQuantitySpec<kind_of_<length>>);
|
||||
static_assert(!detail::IntermediateDerivedQuantitySpec<kind_of_<length>>);
|
||||
static_assert(detail::QuantityKindSpec<kind_of_<length>>);
|
||||
static_assert(QuantitySpec<kind_of_<length_>>);
|
||||
static_assert(!detail::NamedQuantitySpec<kind_of_<length_>>);
|
||||
static_assert(!detail::IntermediateDerivedQuantitySpec<kind_of_<length_>>);
|
||||
static_assert(detail::QuantityKindSpec<kind_of_<length_>>);
|
||||
|
||||
static_assert(QuantitySpec<frequency_>);
|
||||
static_assert(detail::NamedQuantitySpec<frequency_>);
|
||||
@@ -126,10 +126,10 @@ static_assert(!detail::NamedQuantitySpec<decltype(inverse(time))>);
|
||||
static_assert(detail::IntermediateDerivedQuantitySpec<decltype(inverse(time))>);
|
||||
static_assert(!detail::QuantityKindSpec<decltype(inverse(time))>);
|
||||
|
||||
static_assert(QuantitySpec<kind_of_<length / time>>);
|
||||
static_assert(!detail::NamedQuantitySpec<kind_of_<length / time>>);
|
||||
static_assert(detail::IntermediateDerivedQuantitySpec<kind_of_<length / time>>);
|
||||
static_assert(detail::QuantityKindSpec<kind_of_<length / time>>);
|
||||
static_assert(QuantitySpec<kind_of_<std::remove_const_t<decltype(length / time)>>>);
|
||||
static_assert(!detail::NamedQuantitySpec<kind_of_<std::remove_const_t<decltype(length / time)>>>);
|
||||
static_assert(detail::IntermediateDerivedQuantitySpec<kind_of_<std::remove_const_t<decltype(length / time)>>>);
|
||||
static_assert(detail::QuantityKindSpec<kind_of_<std::remove_const_t<decltype(length / time)>>>);
|
||||
|
||||
static_assert(QuantitySpec<decltype(kind_of<length> / kind_of<time>)>);
|
||||
static_assert(!detail::NamedQuantitySpec<decltype(kind_of<length> / kind_of<time>)>);
|
||||
@@ -265,8 +265,8 @@ static_assert(is_of_type<acceleration * mass, derived_quantity_spec<acceleration
|
||||
static_assert(is_of_type<(acceleration * mass).dimension,
|
||||
derived_dimension<dim_length_, dim_mass_, per<mp_units::power<dim_time_, 2>>>>);
|
||||
|
||||
static_assert(is_of_type<kind_of<length> / kind_of<time>, kind_of_<derived_quantity_spec<length_, per<time_>>{}>>);
|
||||
static_assert(is_of_type<kind_of<length / time>, kind_of_<derived_quantity_spec<length_, per<time_>>{}>>);
|
||||
static_assert(is_of_type<kind_of<length> / kind_of<time>, kind_of_<derived_quantity_spec<length_, per<time_>>>>);
|
||||
static_assert(is_of_type<kind_of<length / time>, kind_of_<derived_quantity_spec<length_, per<time_>>>>);
|
||||
|
||||
// power
|
||||
static_assert(is_of_type<pow<0>(length), dimensionless_>);
|
||||
|
Reference in New Issue
Block a user