Skip to content

mp_units::value_cast

Explicit cast of a quantity point's representation type

Synopsis

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

template<typename ToRep, typename FwdQP, RoundingPolicy Policy = truncated_t,
         QuantityPoint QP = std::remove_cvref_t<FwdQP>>
  requires RepresentationOf<ToRep, QP::quantity_spec> && std::constructible_from<ToRep, typename QP::rep> &&
           detail::ValidRoundingPolicyFor<Policy, typename QP::rep, ToRep>
[[nodiscard]] constexpr quantity_point<QP::reference, QP::point_origin, ToRep> 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<int>(quantity_point{1.23 * ms});

Return Value

A quantity point

Note

The return value should not be discarded.

Template Parameters

NameDescription
ToRepa representation type to use for a target quantity point

Parameters

NameDescription
policyan optional rounding policy (truncated when not provided)