mp_units::quantity_cast

Explicit cast of a quantity point type

Synopsis

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

template<
    QuantitySpec auto ToQS,
    typename FwdQP,
    QuantityPoint QP = std::remove_cvref_t<FwdQP>>
requires (mp_units::castable(QP::quantity_spec, ToQS)) &&
          requires { typename quantity_point<make_reference(ToQS, QP::unit), QP::point_origin, typename QP::rep>; }
[[nodiscard]]
constexpr
QuantityPoint auto
quantity_cast(FwdQP&& qp);

Description

This cast converts only a quantity point type. It might be used to force some quantity point type conversions that are not implicitly allowed but are allowed explicitly.

For example:


auto length = isq::length(quantity_point{42 * m});
auto altitude = quantity_cast<isq::altitude>(length);

NOTE

This cast does not affect the underlying value of a number stored in a quantity point.

Return Value

the quantity point with its quantity type recast to ToQS

NOTE

The return value should not be discarded.

Template Parameters

NameDescription
ToQSa quantity specification to use for a target quantity point

Parameters

NameDescription
qpthe quantity point to cast