Explicit cast of a quantity's unit
Declared in <mp-units/framework/value_cast.h>
template<
auto ToU,
typename FwdQ,
RoundingPolicy Policy = truncated_t,
Quantity Q = std::remove_cvref_t<FwdQ>>
requires UnitOf<MP_UNITS_REMOVE_CONST(decltype(ToU)), Q::quantity_spec> &&
detail::ExplicitlyCastable<Q::unit, ToU, typename Q::rep> &&
detail::ValidRoundingPolicyFor<Policy, typename Q::rep, typename Q::rep>
[[nodiscard]]
constexpr
Quantity auto
value_cast(
FwdQ&& q,
Policy = Policy{});
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 d = value_cast<si::second>(1234 * ms); auto e = value_cast<si::second>(1567 * ms, rounded);
The return value should not be discarded.
| Name | Description |
|---|---|
| ToU | a unit to use for a target quantity |
| Name | Description |
|---|---|
| policy | an optional rounding policy (truncated when not provided) |