feat: quantity_spec conversions improved

This commit is contained in:
Mateusz Pusz committed 2024-12-28 14:02:03 +01:00
1 parent b685521a18
commit 06cbfae3b3
26 files changed
+1013 -1147

No files matched your search

@@ -58,12 +58,16 @@ template<QuantitySpec A, QuantitySpec B>
template<QuantitySpec A, QuantitySpec B>
[[nodiscard]] consteval bool have_common_base(A a, B b)
{
constexpr std::size_t a_length = hierarchy_path_length(A{});
constexpr std::size_t b_length = hierarchy_path_length(B{});
if constexpr (a_length > b_length)
return have_common_base_in_hierarchy_of_equal_length(hierarchy_path_advance<a_length - b_length>(a), b);
else
return have_common_base_in_hierarchy_of_equal_length(a, hierarchy_path_advance<b_length - a_length>(b));
if constexpr (is_same_v<A, B>)
return true;
else {
constexpr std::size_t a_length = hierarchy_path_length(A{});
constexpr std::size_t b_length = hierarchy_path_length(B{});
if constexpr (a_length > b_length)
return have_common_base_in_hierarchy_of_equal_length(hierarchy_path_advance<a_length - b_length>(a), b);
else
return have_common_base_in_hierarchy_of_equal_length(a, hierarchy_path_advance<b_length - a_length>(b));
}
}
template<QuantitySpec A, QuantitySpec B>
@@ -91,16 +95,20 @@ template<QuantitySpec A, QuantitySpec B>
template<QuantitySpec Child, QuantitySpec Parent>
[[nodiscard]] consteval bool is_child_of(Child ch, Parent p)
{
if constexpr (Child{} == Parent{})
return std::true_type{};
else {
constexpr std::size_t child_length = hierarchy_path_length(Child{});
constexpr std::size_t parent_length = hierarchy_path_length(Parent{});
if constexpr (parent_length > child_length)
return false;
else
return hierarchy_path_advance<child_length - parent_length>(ch) == p;
}
constexpr std::size_t child_length = hierarchy_path_length(Child{});
constexpr std::size_t parent_length = hierarchy_path_length(Parent{});
if constexpr (parent_length >= child_length)
return false;
else
return hierarchy_path_advance<child_length - parent_length>(ch) == p;
}
[[nodiscard]] consteval QuantitySpec auto get_hierarchy_root(QuantitySpec auto q)
{
if constexpr (requires { q._parent_; })
return get_hierarchy_root(q._parent_);
else
return q;
}
} // namespace mp_units::detail
@@ -172,6 +172,22 @@ struct type_list_split_half;
template<template<typename...> typename List, typename... Types>
struct type_list_split_half<List<Types...>> : type_list_split<List<Types...>, (sizeof...(Types) + 1) / 2> {};
// extract
template<TypeList, TypeList>
struct type_list_extract_impl;
template<template<typename...> typename List, typename... Pre, typename Element, typename... Post>
struct type_list_extract_impl<List<Pre...>, List<Element, Post...>> {
using element = Element;
using rest = List<Pre..., Post...>;
};
template<TypeList List, std::size_t N>
requires(N >= 0) && (type_list_size<List> > N)
struct type_list_extract :
type_list_extract_impl<typename type_list_split<List, N>::first_list,
typename type_list_split<List, N>::second_list> {};
// merge_sorted
template<typename SortedList1, typename SortedList2, template<typename, typename> typename Pred>
struct type_list_merge_sorted_impl;
@@ -76,35 +76,26 @@ struct power_v {
static constexpr ratio exponent{Num, Den...};
};
template<typename Element>
[[nodiscard]] consteval auto get_base(Element element)
template<typename T>
[[nodiscard]] consteval auto get_base(T element)
{
if constexpr (is_specialization_of_v<Element, power_v>)
return Element::base;
if constexpr (is_specialization_of_v<T, power_v>)
return T::base;
else
return element;
}
template<typename Element>
[[nodiscard]] consteval auto get_base_value(Element element)
template<typename T>
[[nodiscard]] consteval auto get_base_value(T element)
{
if constexpr (is_specialization_of_v<Element, power_v>)
return get_base_value(Element::base);
else if constexpr (MagConstant<Element>)
if constexpr (is_specialization_of_v<T, power_v>)
return get_base_value(T::base);
else if constexpr (MagConstant<T>)
return element._value_;
else
return element;
}
template<typename Element>
[[nodiscard]] MP_UNITS_CONSTEVAL ratio get_exponent(Element)
{
if constexpr (is_specialization_of_v<Element, power_v>)
return Element::exponent;
else
return ratio{1};
}
template<auto V, ratio R>
[[nodiscard]] consteval auto power_v_or_T()
{
@@ -71,8 +71,8 @@ concept ValuePreservingTo = Representation<std::remove_cvref_t<FromRep>> && Repr
template<typename QFrom, typename QTo>
concept QuantityConvertibleTo =
Quantity<QFrom> && Quantity<QTo> && QuantitySpecConvertibleTo<QFrom::quantity_spec, QTo::quantity_spec> &&
UnitConvertibleTo<QFrom::unit, QTo::unit> &&
Quantity<QFrom> && Quantity<QTo> && implicitly_convertible(QFrom::quantity_spec, QTo::quantity_spec) &&
(interconvertible(QFrom::unit, QTo::unit)) &&
ValuePreservingTo<typename QFrom::rep, typename QTo::rep, QFrom::unit, QTo::unit> &&
// TODO consider providing constraints of sudo_cast here rather than testing if it can be called (its return type is
// deduced thus the function is evaluated here and may emit truncating conversion or other warnings)
@@ -641,6 +641,10 @@ MP_UNITS_EXPORT_END
} // namespace mp_units
// This specialization overrides `std` defaults for quantities
template<mp_units::Quantity Q1, mp_units::Quantity Q2>
struct std::common_type<Q1, Q2> {};
template<mp_units::Quantity Q1, mp_units::Quantity Q2>
requires requires {
{ mp_units::get_common_reference(Q1::reference, Q2::reference) } -> mp_units::Reference;
@@ -57,7 +57,7 @@ namespace mp_units {
* @tparam ToQS a quantity specification to use for a target quantity
*/
template<QuantitySpec auto ToQS, typename FwdQ, Quantity Q = std::remove_cvref_t<FwdQ>>
requires detail::QuantitySpecCastableTo<Q::quantity_spec, ToQS>
requires(castable(Q::quantity_spec, ToQS)) && detail::WeakUnitOf<MP_UNITS_NONCONST_TYPE(Q::unit), ToQS>
[[nodiscard]] constexpr Quantity auto quantity_cast(FwdQ&& q)
{
return quantity{std::forward<FwdQ>(q).numerical_value_is_an_implementation_detail_, make_reference(ToQS, Q::unit)};
@@ -81,7 +81,7 @@ template<QuantitySpec auto ToQS, typename FwdQ, Quantity Q = std::remove_cvref_t
* @tparam ToQS a quantity specification to use for a target quantity point
*/
template<QuantitySpec auto ToQS, typename FwdQP, QuantityPoint QP = std::remove_cvref_t<FwdQP>>
requires detail::QuantitySpecCastableTo<QP::quantity_spec, ToQS>
requires(castable(QP::quantity_spec, ToQS)) && detail::WeakUnitOf<MP_UNITS_NONCONST_TYPE(QP::unit), ToQS>
[[nodiscard]] constexpr QuantityPoint auto quantity_cast(FwdQP&& qp)
{
return QP{quantity_cast<ToQS>(std::forward<FwdQP>(qp).quantity_from_origin_is_an_implementation_detail_),
@@ -72,13 +72,13 @@ concept QuantityLikeImpl = requires(const T& qty, const Traits<T>::rep& num) {
} // namespace detail
/**
* @brief A concept matching all quantities with provided quantity spec
* @brief A concept matching all quantities of the provided quantity spec
*
* Satisfied by all quantities with a quantity_spec being the instantiation derived from
* the provided quantity_spec type.
* Satisfied by all quantities with the reference satisfying @c ReferenceOf<QS>.
*/
MP_UNITS_EXPORT template<typename Q, auto QS>
concept QuantityOf = Quantity<Q> && QuantitySpecOf<MP_UNITS_NONCONST_TYPE(Q::quantity_spec), QS>;
concept QuantityOf = Quantity<Q> && QuantitySpec<MP_UNITS_REMOVE_CONST(decltype(QS))> &&
ReferenceOf<MP_UNITS_NONCONST_TYPE(Q::reference), QS>;
/**
* @brief A concept matching all external quantities like types
@@ -117,7 +117,7 @@ concept SameAbsolutePointOriginAs =
/**
* @brief A concept matching all quantity points with provided quantity spec
* @brief A concept matching all quantity points of the provided property
*
* Satisfied by all quantity points with a quantity_spec being the instantiation derived from
* the provided quantity_spec type, or quantity points having the origin with the same
@@ -125,7 +125,7 @@ concept SameAbsolutePointOriginAs =
*/
MP_UNITS_EXPORT template<typename QP, auto V>
concept QuantityPointOf =
QuantityPoint<QP> && (QuantitySpecOf<MP_UNITS_NONCONST_TYPE(QP::quantity_spec), V> ||
QuantityPoint<QP> && (ReferenceOf<MP_UNITS_NONCONST_TYPE(QP::reference), V> ||
detail::SameAbsolutePointOriginAs<MP_UNITS_NONCONST_TYPE(QP::absolute_point_origin), V>);
/**
File diff suppressed because it is too large. Load diff
@@ -25,7 +25,6 @@
// IWYU pragma: private, include <mp-units/framework.h>
#include <mp-units/bits/hacks.h>
#include <mp-units/bits/module_macros.h>
#include <mp-units/framework/dimension_concepts.h>
#include <mp-units/framework/symbolic_expression.h>
namespace mp_units {
@@ -39,14 +38,6 @@ struct quantity_spec_interface_base;
MP_UNITS_EXPORT template<typename T>
concept QuantitySpec = detail::SymbolicConstant<T> && std::derived_from<T, detail::quantity_spec_interface_base>;
MP_UNITS_EXPORT
#if MP_UNITS_API_NO_CRTP
template<auto...>
#else
template<typename, auto...>
#endif
struct quantity_spec;
template<typename Q>
struct kind_of_;
@@ -55,93 +46,19 @@ namespace detail {
template<typename T>
concept QuantityKindSpec = QuantitySpec<T> && is_specialization_of<T, kind_of_>;
#if MP_UNITS_API_NO_CRTP
template<auto... Args>
void to_base_specialization_of_quantity_spec(const volatile quantity_spec<Args...>*);
#else
template<typename T, auto... Args>
void to_base_specialization_of_quantity_spec(const volatile quantity_spec<T, Args...>*);
#endif
} // namespace detail
template<typename T>
constexpr bool is_derived_from_specialization_of_quantity_spec =
requires(T* type) { to_base_specialization_of_quantity_spec(type); };
MP_UNITS_EXPORT template<QuantitySpec From, QuantitySpec To>
[[nodiscard]] consteval bool implicitly_convertible(From from, To to);
/**
* @brief Concept matching all named quantity specification types
* @brief A concept matching all quantity specifications of a provided quantity spec value
*
* Satisfied by all types that derive from `quantity_spec`.
* Satisfied by all quantity specifications that are implicitly convertible to the provided @c QS
* value.
*/
template<typename T>
concept NamedQuantitySpec =
QuantitySpec<T> && is_derived_from_specialization_of_quantity_spec<T> && (!QuantityKindSpec<T>);
} // namespace detail
template<detail::SymbolicConstant... Expr>
struct derived_quantity_spec;
namespace detail {
/**
* @brief Concept matching all derived quantity specification types
*
* Satisfied by all `derived_quantity_spec` specializations.
*
* @note Deriving a strong type from it is considered a logic error and thus is
* explicitly not supported here.
*/
template<typename T>
concept DerivedQuantitySpec =
QuantitySpec<T> &&
(is_specialization_of<T, derived_quantity_spec> ||
(QuantityKindSpec<T> && is_specialization_of<MP_UNITS_NONCONST_TYPE(T::_quantity_spec_), derived_quantity_spec>));
} // namespace detail
MP_UNITS_EXPORT template<QuantitySpec Q>
[[nodiscard]] consteval detail::QuantityKindSpec auto get_kind(Q q);
namespace detail {
template<QuantitySpec Child, QuantitySpec Parent>
[[nodiscard]] consteval bool is_child_of(Child ch, Parent p);
template<auto Child, auto Parent>
concept ChildQuantitySpecOf = (is_child_of(Child, Parent));
template<auto To, auto From>
concept NestedQuantityKindSpecOf =
QuantitySpec<MP_UNITS_REMOVE_CONST(decltype(From))> && QuantitySpec<MP_UNITS_REMOVE_CONST(decltype(To))> &&
(get_kind(From) != get_kind(To)) && ChildQuantitySpecOf<To, get_kind(From)._quantity_spec_>;
template<auto From, auto To>
concept QuantitySpecConvertibleTo =
QuantitySpec<MP_UNITS_REMOVE_CONST(decltype(From))> && QuantitySpec<MP_UNITS_REMOVE_CONST(decltype(To))> &&
implicitly_convertible(From, To);
template<auto From, auto To>
concept QuantitySpecExplicitlyConvertibleTo =
QuantitySpec<MP_UNITS_REMOVE_CONST(decltype(From))> && QuantitySpec<MP_UNITS_REMOVE_CONST(decltype(To))> &&
explicitly_convertible(From, To);
template<auto From, auto To>
concept QuantitySpecCastableTo = QuantitySpec<MP_UNITS_REMOVE_CONST(decltype(From))> &&
QuantitySpec<MP_UNITS_REMOVE_CONST(decltype(To))> && castable(From, To);
} // namespace detail
MP_UNITS_EXPORT template<typename T, auto QS>
concept QuantitySpecOf =
QuantitySpec<T> && QuantitySpec<MP_UNITS_REMOVE_CONST(decltype(QS))> && detail::QuantitySpecConvertibleTo<T{}, QS> &&
// the below is to make the following work
// static_assert(ReferenceOf<si::radian, isq::angular_measure>);
// static_assert(!ReferenceOf<si::radian, dimensionless>);
// static_assert(!ReferenceOf<isq::angular_measure[si::radian], dimensionless>
// static_assert(ReferenceOf<one, isq::angular_measure>);
// static_assert(!ReferenceOf<dimensionless[one], isq::angular_measure>);
!detail::NestedQuantityKindSpecOf<T{}, QS> &&
(detail::QuantityKindSpec<T> || !detail::NestedQuantityKindSpecOf<QS, T{}>);
QuantitySpec<T> && QuantitySpec<MP_UNITS_REMOVE_CONST(decltype(QS))> && (mp_units::implicitly_convertible(T{}, QS));
} // namespace mp_units
@@ -187,24 +187,6 @@ struct reference {
{
return {};
}
template<typename Q2, typename U2>
[[nodiscard]] friend consteval bool convertible(reference, reference<Q2, U2>)
{
return implicitly_convertible(Q{}, Q2{}) && convertible(U{}, U2{});
}
template<AssociatedUnit U2>
[[nodiscard]] friend consteval bool convertible(reference, U2 u2)
{
return implicitly_convertible(Q{}, get_quantity_spec(u2)) && convertible(U{}, u2);
}
template<AssociatedUnit U1>
[[nodiscard]] friend consteval bool convertible(U1 u1, reference)
{
return implicitly_convertible(get_quantity_spec(u1), Q{}) && convertible(u1, U{});
}
};
@@ -60,13 +60,13 @@ template<typename T>
concept Reference = AssociatedUnit<T> || is_specialization_of<T, reference>;
/**
* @brief A concept matching all references with provided quantity spec
* @brief A concept matching all references of the provided quantity spec
*
* Satisfied by all references with a quantity_spec being the instantiation derived from
* the provided quantity_spec type.
* Satisfied by all references for which @c QuantitySpecOf<QS> is true.
*/
template<typename T, auto QS>
concept ReferenceOf = Reference<T> && QuantitySpecOf<decltype(get_quantity_spec(T{})), QS>;
concept ReferenceOf = Reference<T> && QuantitySpec<MP_UNITS_REMOVE_CONST(decltype(QS))> &&
QuantitySpecOf<decltype(get_quantity_spec(T{})), QS>;
MP_UNITS_EXPORT_END
@@ -143,8 +143,29 @@ constexpr bool is_specialization_of_power = false;
template<typename F, int... Ints>
constexpr bool is_specialization_of_power<power<F, Ints...>> = true;
template<typename T>
[[nodiscard]] consteval auto get_factor(T element)
{
if constexpr (is_specialization_of_power<T>)
return typename T::_factor_{};
else
return element;
}
template<typename T>
[[nodiscard]] MP_UNITS_CONSTEVAL ratio get_exponent(T)
{
// this covers both `power` and `power_v`
if constexpr (requires { T::_exponent_; })
return T::_exponent_;
else if constexpr (requires { T::exponent; })
return T::exponent;
else
return ratio{1};
};
template<SymbolicArg T, ratio R>
consteval auto power_or_T_impl()
[[nodiscard]] consteval auto power_or_T_impl()
{
if constexpr (is_specialization_of_power<T>) {
return power_or_T_impl<typename T::_factor_, T::_exponent_ * R>();
@@ -66,7 +66,7 @@ struct system_reference {
static constexpr auto coherent_unit = CoU;
template<Unit U>
requires detail::UnitConvertibleTo<coherent_unit, U{}>
requires(interconvertible(coherent_unit, U{}))
#if MP_UNITS_COMP_MSVC
[[nodiscard]] constexpr decltype(reference<MP_UNITS_REMOVE_CONST(decltype(Q)), U>{}) operator[](U) const
#else
+22 -18
View File
@@ -126,30 +126,34 @@ constexpr auto get_canonical_unit_result = get_canonical_unit_impl(U{}, U{});
namespace detail {
template<typename From, typename To>
concept PotentiallyConvertibleTo = Unit<From> && Unit<To> &&
((AssociatedUnit<From> && AssociatedUnit<To> &&
implicitly_convertible(get_quantity_spec(From{}), get_quantity_spec(To{}))) ||
(!AssociatedUnit<From> && !AssociatedUnit<To>));
// We are using a helper concept to benefit from short-circuiting
template<typename U1, typename U2>
concept PotentiallyInterConvertibleTo = Unit<U1> && Unit<U2> &&
(!AssociatedUnit<U1> || !AssociatedUnit<U2> ||
explicitly_convertible(get_quantity_spec(U1{}), get_quantity_spec(U2{})));
} // namespace detail
}
// convertible
template<Unit From, Unit To>
[[nodiscard]] consteval bool convertible(From from, To to)
// interconvertible
template<Unit U1, Unit U2>
[[nodiscard]] consteval bool interconvertible(U1 u1, U2 u2)
{
if constexpr (is_same_v<From, To>)
if constexpr (is_same_v<U1, U2>)
return true;
else if constexpr (detail::PotentiallyConvertibleTo<From, To>)
return is_same_v<decltype(get_canonical_unit(from).reference_unit),
decltype(get_canonical_unit(to).reference_unit)>;
else if constexpr (detail::PotentiallyInterConvertibleTo<U1, U2>)
return is_same_v<decltype(get_canonical_unit(u1).reference_unit), decltype(get_canonical_unit(u2).reference_unit)>;
else
return false;
}
template<UnitMagnitude auto M, Unit U>
requires(M != detail::unit_magnitude<>{} && M != mag<1>)
struct scaled_unit;
template<detail::SymbolicConstant... Expr>
struct derived_unit;
MP_UNITS_EXPORT struct one;
namespace detail {
struct unit_interface {
@@ -424,7 +428,7 @@ struct prefixed_unit : decltype(M * U)::_base_type_ {
namespace detail {
template<Unit U1, Unit U2>
requires(convertible(U1{}, U2{}))
requires(interconvertible(U1{}, U2{}))
[[nodiscard]] consteval Unit auto get_common_scaled_unit(U1, U2)
{
constexpr auto canonical_lhs = get_canonical_unit(U1{});
@@ -668,7 +672,7 @@ inline constexpr auto ppm = parts_per_million;
[[nodiscard]] consteval Unit auto get_common_unit(Unit auto u) { return u; }
template<Unit U1, Unit U2>
requires(convertible(U1{}, U2{}))
requires(interconvertible(U1{}, U2{}))
[[nodiscard]] consteval Unit auto get_common_unit(U1 u1, U2 u2)
{
if constexpr (is_same_v<U1, U2>)
@@ -729,7 +733,7 @@ using collapse_common_unit = type_list_unique<
} // namespace detail
template<Unit... Us, Unit NewUnit>
requires(convertible(common_unit<Us...>{}, NewUnit{}))
requires(interconvertible(common_unit<Us...>{}, NewUnit{}))
[[nodiscard]] consteval Unit auto get_common_unit(common_unit<Us...>, NewUnit)
{
using type = detail::collapse_common_unit<NewUnit, Us...>;
@@ -740,7 +744,7 @@ template<Unit... Us, Unit NewUnit>
}
template<Unit... Us, Unit NewUnit>
requires(convertible(common_unit<Us...>{}, NewUnit{}))
requires(interconvertible(common_unit<Us...>{}, NewUnit{}))
[[nodiscard]] consteval Unit auto get_common_unit(NewUnit nu, common_unit<Us...> cu)
{
return get_common_unit(cu, nu);
@@ -25,7 +25,6 @@
// IWYU pragma: private, include <mp-units/framework.h>
#include <mp-units/bits/module_macros.h>
#include <mp-units/framework/quantity_spec_concepts.h>
#include <mp-units/framework/symbol_text.h>
#include <mp-units/framework/symbolic_expression.h>
#include <mp-units/framework/unit_magnitude.h>
@@ -45,15 +44,9 @@ struct unit_interface;
MP_UNITS_EXPORT template<typename T>
concept Unit = detail::SymbolicConstant<T> && std::derived_from<T, detail::unit_interface>;
template<UnitMagnitude auto M, Unit U>
requires(M != detail::unit_magnitude<>{} && M != mag<1>)
struct scaled_unit;
MP_UNITS_EXPORT template<symbol_text Symbol, auto...>
struct named_unit;
MP_UNITS_EXPORT struct one;
/**
* @brief A concept to be used to define prefixes for a unit
*/
@@ -100,24 +93,21 @@ concept AssociatedUnit = Unit<U> && detail::has_associated_quantity(U{});
/**
* @brief A concept matching all units associated with the provided quantity spec
*
* Satisfied by all units associated with the quantity_spec being the instantiation derived from
* the provided quantity_spec type.
* Satisfied by all units for which an associated quantity spec is implicitly convertible to
* the provided @c QS value.
*/
MP_UNITS_EXPORT template<typename U, auto QS>
concept UnitOf =
AssociatedUnit<U> && QuantitySpec<MP_UNITS_REMOVE_CONST(decltype(QS))> &&
detail::QuantitySpecConvertibleTo<get_quantity_spec(U{}), QS> &&
// the below is to make `dimensionless[radian]` invalid
(get_kind(QS) == get_kind(get_quantity_spec(U{})) || !detail::NestedQuantityKindSpecOf<get_quantity_spec(U{}), QS>);
concept UnitOf = AssociatedUnit<U> && QuantitySpec<MP_UNITS_REMOVE_CONST(decltype(QS))> &&
(implicitly_convertible(get_quantity_spec(U{}), QS));
MP_UNITS_EXPORT template<Unit From, Unit To>
[[nodiscard]] consteval bool convertible(From from, To to);
MP_UNITS_EXPORT template<Unit U1, Unit U2>
[[nodiscard]] consteval bool interconvertible(U1 u1, U2 u2);
namespace detail {
template<auto From, auto To>
concept UnitConvertibleTo =
Unit<MP_UNITS_REMOVE_CONST(decltype(From))> && Unit<MP_UNITS_REMOVE_CONST(decltype(To))> && (convertible(From, To));
template<typename U, auto QS>
concept WeakUnitOf =
Unit<U> && QuantitySpec<MP_UNITS_REMOVE_CONST(decltype(QS))> && ((!AssociatedUnit<U>) || UnitOf<U, QS>);
/**
* @brief A concept matching all units compatible with the provided unit and quantity spec
@@ -125,10 +115,10 @@ concept UnitConvertibleTo =
* Satisfied by all units that have the same canonical reference as `U2` and in case they
* have associated quantity specification it should satisfy `UnitOf<QS>`.
*/
MP_UNITS_EXPORT template<typename U, auto FromU, auto QS>
template<typename U, auto FromU, auto QS>
concept UnitCompatibleWith =
Unit<U> && Unit<MP_UNITS_REMOVE_CONST(decltype(FromU))> && QuantitySpec<MP_UNITS_REMOVE_CONST(decltype(QS))> &&
(!AssociatedUnit<U> || UnitOf<U, QS>) && detail::UnitConvertibleTo<FromU, U{}>;
WeakUnitOf<U, QS> && (interconvertible(FromU, U{}));
template<typename T>
concept OffsetUnit = Unit<T> && requires { T::_point_origin_; };
@@ -44,8 +44,8 @@ namespace mp_units {
*
* @tparam ToU a unit to use for a target quantity
*/
template<Unit auto ToU, typename FwdQ, Quantity Q = std::remove_cvref_t<FwdQ>>
requires(convertible(Q::reference, ToU))
template<auto ToU, typename FwdQ, Quantity Q = std::remove_cvref_t<FwdQ>>
requires detail::UnitCompatibleWith<MP_UNITS_REMOVE_CONST(decltype(ToU)), Q::unit, Q::quantity_spec>
[[nodiscard]] constexpr Quantity auto value_cast(FwdQ&& q)
{
return detail::sudo_cast<quantity<detail::make_reference(Q::quantity_spec, ToU), typename Q::rep>>(
@@ -81,16 +81,16 @@ template<Representation ToRep, typename FwdQ, Quantity Q = std::remove_cvref_t<F
* @tparam ToRep a representation type to use for the target quantity
*/
template<Unit auto ToU, Representation ToRep, typename FwdQ, Quantity Q = std::remove_cvref_t<FwdQ>>
requires(convertible(Q::reference, ToU)) && RepresentationOf<ToRep, Q::quantity_spec> &&
std::constructible_from<ToRep, typename Q::rep>
requires detail::UnitCompatibleWith<MP_UNITS_REMOVE_CONST(decltype(ToU)), Q::unit, Q::quantity_spec> &&
RepresentationOf<ToRep, Q::quantity_spec> && std::constructible_from<ToRep, typename Q::rep>
[[nodiscard]] constexpr Quantity auto value_cast(FwdQ&& q)
{
return detail::sudo_cast<quantity<detail::make_reference(Q::quantity_spec, ToU), ToRep>>(std::forward<FwdQ>(q));
}
template<Representation ToRep, Unit auto ToU, typename FwdQ, Quantity Q = std::remove_cvref_t<FwdQ>>
requires(convertible(Q::reference, ToU)) && RepresentationOf<ToRep, Q::quantity_spec> &&
std::constructible_from<ToRep, typename Q::rep>
requires detail::UnitCompatibleWith<MP_UNITS_REMOVE_CONST(decltype(ToU)), Q::unit, Q::quantity_spec> &&
RepresentationOf<ToRep, Q::quantity_spec> && std::constructible_from<ToRep, typename Q::rep>
[[nodiscard]] constexpr Quantity auto value_cast(FwdQ&& q)
{
return value_cast<ToU, ToRep>(std::forward<FwdQ>(q));
@@ -112,8 +112,8 @@ template<Representation ToRep, Unit auto ToU, typename FwdQ, Quantity Q = std::r
* @tparam ToQ a target quantity type to which to cast the representation
*/
template<Quantity ToQ, typename FwdQ, Quantity Q = std::remove_cvref_t<FwdQ>>
requires(convertible(Q::reference, ToQ::unit)) &&
(ToQ::quantity_spec == Q::quantity_spec) && std::constructible_from<typename ToQ::rep, typename Q::rep>
requires detail::UnitCompatibleWith<MP_UNITS_NONCONST_TYPE(ToQ::unit), Q::unit, Q::quantity_spec> &&
(ToQ::quantity_spec == Q::quantity_spec) && std::constructible_from<typename ToQ::rep, typename Q::rep>
[[nodiscard]] constexpr Quantity auto value_cast(FwdQ&& q)
{
return detail::sudo_cast<ToQ>(std::forward<FwdQ>(q));
@@ -130,7 +130,7 @@ template<Quantity ToQ, typename FwdQ, Quantity Q = std::remove_cvref_t<FwdQ>>
* @tparam ToU a unit to use for a target quantity point
*/
template<Unit auto ToU, typename FwdQP, QuantityPoint QP = std::remove_cvref_t<FwdQP>>
requires(convertible(QP::reference, ToU))
requires detail::UnitCompatibleWith<MP_UNITS_REMOVE_CONST(decltype(ToU)), QP::unit, QP::quantity_spec>
[[nodiscard]] constexpr QuantityPoint auto value_cast(FwdQP&& qp)
{
return quantity_point{value_cast<ToU>(std::forward<FwdQP>(qp).quantity_from_origin_is_an_implementation_detail_),
@@ -167,8 +167,8 @@ template<Representation ToRep, typename FwdQP, QuantityPoint QP = std::remove_cv
* @tparam ToRep a representation type to use for the target quantity
*/
template<Unit auto ToU, Representation ToRep, typename FwdQP, QuantityPoint QP = std::remove_cvref_t<FwdQP>>
requires(convertible(QP::reference, ToU)) && RepresentationOf<ToRep, QP::quantity_spec> &&
std::constructible_from<ToRep, typename QP::rep>
requires detail::UnitCompatibleWith<MP_UNITS_REMOVE_CONST(decltype(ToU)), QP::unit, QP::quantity_spec> &&
RepresentationOf<ToRep, QP::quantity_spec> && std::constructible_from<ToRep, typename QP::rep>
[[nodiscard]] constexpr QuantityPoint auto value_cast(FwdQP&& qp)
{
return quantity_point{
@@ -177,8 +177,8 @@ template<Unit auto ToU, Representation ToRep, typename FwdQP, QuantityPoint QP =
}
template<Representation ToRep, Unit auto ToU, typename FwdQP, QuantityPoint QP = std::remove_cvref_t<FwdQP>>
requires(convertible(QP::reference, ToU)) && RepresentationOf<ToRep, QP::quantity_spec> &&
std::constructible_from<ToRep, typename QP::rep>
requires detail::UnitCompatibleWith<MP_UNITS_REMOVE_CONST(decltype(ToU)), QP::unit, QP::quantity_spec> &&
RepresentationOf<ToRep, QP::quantity_spec> && std::constructible_from<ToRep, typename QP::rep>
[[nodiscard]] constexpr QuantityPoint auto value_cast(FwdQP&& qp)
{
return value_cast<ToU, ToRep>(std::forward<FwdQP>(qp));
@@ -201,8 +201,8 @@ template<Representation ToRep, Unit auto ToU, typename FwdQP, QuantityPoint QP =
* @tparam ToQ a target quantity type to which to cast the representation of the point
*/
template<Quantity ToQ, typename FwdQP, QuantityPoint QP = std::remove_cvref_t<FwdQP>>
requires(convertible(QP::reference, ToQ::unit)) &&
(ToQ::quantity_spec == QP::quantity_spec) && std::constructible_from<typename ToQ::rep, typename QP::rep>
requires detail::UnitCompatibleWith<MP_UNITS_NONCONST_TYPE(ToQ::unit), QP::unit, QP::quantity_spec> &&
(ToQ::quantity_spec == QP::quantity_spec) && std::constructible_from<typename ToQ::rep, typename QP::rep>
[[nodiscard]] constexpr QuantityPoint auto value_cast(FwdQP&& qp)
{
return quantity_point{value_cast<ToQ>(std::forward<FwdQP>(qp).quantity_from_origin_is_an_implementation_detail_),
@@ -238,9 +238,10 @@ template<Quantity ToQ, typename FwdQP, QuantityPoint QP = std::remove_cvref_t<Fw
* @tparam ToQP a target quantity point type to which to cast the representation of the point
*/
template<QuantityPoint ToQP, typename FwdQP, QuantityPoint QP = std::remove_cvref_t<FwdQP>>
requires(convertible(QP::reference, ToQP::unit)) && (ToQP::quantity_spec == QP::quantity_spec) &&
(detail::same_absolute_point_origins(ToQP::point_origin, QP::point_origin)) &&
std::constructible_from<typename ToQP::rep, typename QP::rep>
requires detail::UnitCompatibleWith<MP_UNITS_NONCONST_TYPE(ToQP::unit), QP::unit, QP::quantity_spec> &&
(ToQP::quantity_spec == QP::quantity_spec) &&
(detail::same_absolute_point_origins(ToQP::point_origin, QP::point_origin)) &&
std::constructible_from<typename ToQP::rep, typename QP::rep>
[[nodiscard]] constexpr QuantityPoint auto value_cast(FwdQP&& qp)
{
return detail::sudo_cast<ToQP>(std::forward<FwdQP>(qp));