mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-29 18:07:16 +02:00
refactor: UnitCompatibleWith
is now exposition-only
This commit is contained in:
@ -148,16 +148,6 @@ concept with an associated quantity type implicitly convertible to `V`.
|
||||
[nested quantity kind within the dimensionless quantities tree](dimensionless_quantities.md/#nested-quantity-kinds).
|
||||
|
||||
|
||||
### `UnitCompatibleWith<T, V1, V2>` { #UnitCompatibleWith }
|
||||
|
||||
`UnitCompatibleWith` concept is satisfied for all units `T` when:
|
||||
|
||||
- `V1` is a [`Unit`](#Unit),
|
||||
- `V2` is a [`QuantitySpec`](#QuantitySpec),
|
||||
- `T` and `V1` are defined in terms of the same reference unit,
|
||||
- if `T` is an [`AssociatedUnit`](#AssociatedUnit) it should satisfy [`UnitOf<V2>`](#UnitOf).
|
||||
|
||||
|
||||
## `Reference<T>` { #Reference }
|
||||
|
||||
`Reference` concept is satisfied by all [quantity reference](../../appendix/glossary.md#reference)
|
||||
|
@ -192,14 +192,14 @@ public:
|
||||
quantity& operator=(quantity&&) = default;
|
||||
|
||||
// unit conversions
|
||||
template<UnitCompatibleWith<unit, quantity_spec> ToU>
|
||||
template<detail::UnitCompatibleWith<unit, quantity_spec> ToU>
|
||||
requires detail::QuantityConvertibleTo<quantity, quantity<detail::make_reference(quantity_spec, ToU{}), Rep>>
|
||||
[[nodiscard]] constexpr QuantityOf<quantity_spec> auto in(ToU) const
|
||||
{
|
||||
return quantity<detail::make_reference(quantity_spec, ToU{}), Rep>{*this};
|
||||
}
|
||||
|
||||
template<UnitCompatibleWith<unit, quantity_spec> ToU>
|
||||
template<detail::UnitCompatibleWith<unit, quantity_spec> ToU>
|
||||
requires requires(quantity q) { value_cast<ToU{}>(q); }
|
||||
[[nodiscard]] constexpr QuantityOf<quantity_spec> auto force_in(ToU) const
|
||||
{
|
||||
@ -230,14 +230,14 @@ public:
|
||||
= delete;
|
||||
#endif
|
||||
|
||||
template<UnitCompatibleWith<unit, quantity_spec> U>
|
||||
template<detail::UnitCompatibleWith<unit, quantity_spec> U>
|
||||
requires detail::QuantityConvertibleTo<quantity, quantity<detail::make_reference(quantity_spec, U{}), Rep>>
|
||||
[[nodiscard]] constexpr rep numerical_value_in(U) const noexcept
|
||||
{
|
||||
return (*this).in(U{}).numerical_value_is_an_implementation_detail_;
|
||||
}
|
||||
|
||||
template<UnitCompatibleWith<unit, quantity_spec> U>
|
||||
template<detail::UnitCompatibleWith<unit, quantity_spec> U>
|
||||
requires requires(quantity q) { value_cast<U{}>(q); }
|
||||
[[nodiscard]] constexpr rep force_numerical_value_in(U) const noexcept
|
||||
{
|
||||
|
@ -277,14 +277,14 @@ public:
|
||||
}
|
||||
|
||||
// unit conversions
|
||||
template<UnitCompatibleWith<unit, quantity_spec> ToU>
|
||||
template<detail::UnitCompatibleWith<unit, quantity_spec> ToU>
|
||||
requires detail::QuantityConvertibleTo<quantity_type, quantity<detail::make_reference(quantity_spec, ToU{}), Rep>>
|
||||
[[nodiscard]] constexpr QuantityPointOf<quantity_spec> auto in(ToU) const
|
||||
{
|
||||
return ::mp_units::quantity_point{quantity_ref_from(PO).in(ToU{}), PO};
|
||||
}
|
||||
|
||||
template<UnitCompatibleWith<unit, quantity_spec> ToU>
|
||||
template<detail::UnitCompatibleWith<unit, quantity_spec> ToU>
|
||||
requires requires(quantity_type q) { value_cast<ToU{}>(q); }
|
||||
[[nodiscard]] constexpr QuantityPointOf<quantity_spec> auto force_in(ToU) const
|
||||
{
|
||||
|
@ -197,8 +197,6 @@ template<auto From, auto To>
|
||||
concept UnitConvertibleTo =
|
||||
Unit<MP_UNITS_REMOVE_CONST(decltype(From))> && Unit<MP_UNITS_REMOVE_CONST(decltype(To))> && (convertible(From, To));
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/**
|
||||
* @brief A concept matching all units compatible with the provided unit and quantity spec
|
||||
*
|
||||
@ -210,11 +208,9 @@ 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{}>;
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<typename T>
|
||||
concept OffsetUnit = Unit<T> && requires { T::point_origin; };
|
||||
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
} // namespace mp_units
|
||||
|
Reference in New Issue
Block a user