Explicit cast of a quantity point's unit

Synopsis

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

template<
    Unit auto ToU,
    typename FwdQP,
    QuantityPoint QP = std::remove_cvref_t<FwdQP>>
requires (MP_UNITS_WEAK_UNIT_OF(MP_UNITS_REMOVE_CONST(decltype(ToU)), QP::quantity_spec)) &&
          detail::SaneScaling<QP::unit, ToU, typename QP::rep>
[[nodiscard]]
constexpr
QuantityPoint auto
value_cast(FwdQP&& qp);

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});

Template Parameters

Name

Description

ToU

a unit to use for a target quantity point

Created with MrDocs