mp_units::value_cast¶
Explicit cast of a quantity point's unit and representation type
Synopsis¶
Declared in <mp-units/framework/value_cast.h>
template<Unit auto ToU, typename ToRep, typename FwdQP, RoundingPolicy Policy = truncated_t,
QuantityPoint QP = std::remove_cvref_t<FwdQP>>
requires UnitOf<MP_UNITS_NTTP_TYPE(ToU), QP::quantity_spec> && RepresentationOf<ToRep, QP::quantity_spec> &&
std::constructible_from<ToRep, typename QP::rep> && detail::ExplicitlyCastable<QP::unit, ToU, ToRep> &&
detail::ValidRoundingPolicyFor<Policy, typename QP::rep, ToRep>
[[nodiscard]] constexpr QuantityPoint auto value_cast(FwdQP&& qp, Policy 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.
auto qp = value_cast<us, int>(quantity_point{1.23 * ms});
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 |
Parameters¶
| Name | Description |
|---|---|
| policy | an optional rounding policy (truncated when not provided) |