5 Quantities and units library [quantities]

5.6 Quantity [qty]

5.6.2 Interoperability [qty.like]

The interfaces specified in this subclause and subclause [qty.pt.like] are used by quantity and quantity_point to specify conversions with other types representing quantities.
[Note 1: 
[qty.chrono] implements them for std​::​chrono​::​duration and std​::​chrono​::​time_point.
— end note]
template<typename T, template<typename> typename Traits> concept qty-like-impl = requires(const T& qty, const Traits<T>::rep& num) { // exposition only { Traits<T>::to_numerical_value(qty) } -> std::same_as<typename Traits<T>::rep>; { Traits<T>::from_numerical_value(num) } -> std::same_as<T>; requires std::same_as<decltype(Traits<T>::explicit_import), const bool>; requires std::same_as<decltype(Traits<T>::explicit_export), const bool>; typename std::bool_constant<Traits<T>::explicit_import>; typename std::bool_constant<Traits<T>::explicit_export>; }; template<typename T> concept QuantityLike = !Quantity<T> && qty-like-impl<T, quantity_like_traits> && requires { typename quantity<quantity_like_traits<T>::reference, typename quantity_like_traits<T>::rep>; };
In the following descriptions, let
  • Traits be quantity_like_traits or quantity_point_like_traits,
  • Q be a type for which Traits<Q> is specialized,
  • qty be an lvalue of type const Q, and
  • num be an lvalue of type const Traits<Q>​::​rep.
Q models qty-like-impl<Traits> if and only if:
  • Traits<Q>​::​to_numerical_value(qty) returns the numerical value (IEC 60050, 112-01-29) of qty.
  • Traits<Q>​::​from_numerical_value(num) returns a Q with numerical value num.
  • If Traits is quantity_point_like_traits, both numerical values are offset from Traits<Q>​::​point_origin.
If the following expression is true, the specified conversion will be explicit.
  • Traits<Q>​::​explicit_import for the conversion from Q to this library's type.
  • Traits<Q>​::​explicit_export for the conversion from this library's type to Q.