Skip to content

mp_units::quantity_cast

Explicit cast of a quantity type

Synopsis

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

template<QuantitySpec auto ToQS, typename FwdQ, Quantity Q = std::remove_cvref_t<FwdQ>>
  requires(mp_units::castable(Q::quantity_spec, ToQS)) &&
          requires { typename quantity<make_reference(ToQS, Q::unit), typename Q::rep>; }
[[nodiscard]] constexpr Quantity auto quantity_cast(FwdQ&& q);

Description

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

For example:


auto length = isq::length(42 * m);
auto distance = quantity_cast<isq::distance>(length);

NOTE

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

Return Value

Note

The return value should not be discarded.

Template Parameters

NameDescription
ToQSa quantity specification to use for a target quantity