5 Quantities and units library [quantities]

5.6 Quantity [qty]

5.6.15 Non-member conversions [qty.non.mem.conv]

template<Quantity To, typename FwdFrom, Quantity From = std::remove_cvref_t<FwdFrom>> requires see below constexpr To sudo-cast(FwdFrom&& q); // exposition only
Returns: TBD.
value_cast is an explicit cast that allows truncation.
template<Unit auto ToU, typename FwdQ, Quantity Q = std::remove_cvref_t<FwdQ>> requires(convertible(Q::reference, ToU)) constexpr Quantity auto value_cast(FwdQ&& q);
Effects: Equivalent to: return sudo-cast<quantity<make-reference(Q::quantity_spec, ToU), typename Q::rep>>( std::forward<FwdQ>(q));
template<Representation ToRep, typename FwdQ, Quantity Q = std::remove_cvref_t<FwdQ>> requires RepresentationOf<ToRep, Q::quantity_spec> && std::constructible_from<ToRep, typename Q::rep> constexpr quantity<Q::reference, ToRep> value_cast(FwdQ&& q);
Effects: Equivalent to: return sudo-cast<quantity<Q::reference, ToRep>>(std::forward<FwdQ>(q));
template<Unit auto ToU, Representation ToRep, typename FwdQ, Quantity Q = std::remove_cvref_t<FwdQ>> requires see below constexpr Quantity auto value_cast(FwdQ&& q); template<Representation ToRep, Unit auto ToU, typename FwdQ, Quantity Q = std::remove_cvref_t<FwdQ>> requires see below constexpr Quantity auto value_cast(FwdQ&& q);
Effects: Equivalent to: return sudo-cast<quantity<make-reference(Q::quantity_spec, ToU), ToRep>>( std::forward<FwdQ>(q));
Remarks: The expression in the requires-clause is equivalent to: (convertible(Q::reference, ToU)) && RepresentationOf<ToRep, Q::quantity_spec> && std::constructible_from<ToRep, typename Q::rep>
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> constexpr Quantity auto value_cast(FwdQ&& q);
Effects: Equivalent to: return sudo-cast<ToQ>(std​::​forward<FwdQ>(q));
quantity_cast is an explicit cast that allows converting to more specific quantities.
[Example 1: auto length = isq::length(42 * m); auto distance = quantity_cast<isq::distance>(length); — end example]
template<QuantitySpec auto ToQS, typename FwdQ, Quantity Q = std::remove_cvref_t<FwdQ>> requires QuantitySpecCastableTo<Q::quantity_spec, ToQS> constexpr Quantity auto quantity_cast(FwdQ&& q);
Effects: Equivalent to: return quantity{std::forward<FwdQ>(q).numerical-value, make-reference(ToQS, Q::unit)};