Skip to content

mp_units::value_cast

Explicit cast of a quantity point's unit

Synopsis

Declared in <mp-units/framework/value_cast.h>

template<Unit auto ToU, typename FwdQP,
         /* implementation-defined */ Policy = truncated_t,
         QuantityPoint QP = std::remove_cvref_t<FwdQP>>
  requires UnitOf<decltype(ToU), QP::quantity_spec> &&
           detail::UnitChangeCastable<QP::unit, ToU, typename QP::rep> &&
           detail::ValidRoundingPolicyFor<Policy, typename QP::rep, typename QP::rep>
[[nodiscard]] constexpr QuantityPoint auto value_cast(FwdQP&& qp,
                                                      Policy policy = Policy{});

Description

Implicit conversions between quantity points 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<si::second>(quantity_point{1234 * ms});

Return Value

Note

The return value should not be discarded.

Template Parameters

NameDescription
ToUa unit to use for a target quantity point
Policythe rounding policy, truncated unless a policy is passed