mp_units::value_cast¶
Explicit cast of a quantity's unit and representation type
Synopsis¶
Declared in <mp-units/framework/value_cast.h>
template<Unit auto ToU, typename ToRep, typename FwdQ,
/* implementation-defined */ Policy = truncated_t,
Quantity Q = std::remove_cvref_t<FwdQ>>
requires UnitOf<decltype(ToU), Q::quantity_spec> &&
RepresentationOf<ToRep, Q::quantity_spec> &&
std::constructible_from<ToRep, typename Q::rep> &&
detail::UnitChangeCastable<Q::unit, ToU, ToRep> &&
detail::ValidRoundingPolicyFor<Policy, typename Q::rep, ToRep>
[[nodiscard]] constexpr Quantity auto value_cast(FwdQ&& q, Policy = Policy{});
Description¶
Implicit conversions between quantities of different types are allowed only for "safe" (e.g. non-truncating) conversion. In truncating cases an explicit cast have to be used.
Return Value¶
Note
The return value should not be discarded.
Template Parameters¶
| Name | Description |
|---|---|
| ToU | a unit to use for the target quantity |
| ToRep | a representation type to use for the target quantity |
| Policy | the rounding policy, truncated unless a policy is passed |