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, RoundingPolicy Policy = truncated_t,
         QuantityPoint QP = std::remove_cvref_t<FwdQP>>
  requires UnitOf<MP_UNITS_NTTP_TYPE(ToU), QP::quantity_spec> &&
           detail::ExplicitlyCastable<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

Parameters

NameDescription
policyan optional rounding policy (truncated when not provided)