Explicit cast of a quantity's representation type and unit
Synopsis
Declared in <mp‐units/framework/value_cast.h>
template<
typename ToRep,
Unit auto ToU,
typename FwdQ,
RoundingPolicy Policy = truncated_t,
Quantity Q = std::remove_cvref_t<FwdQ>>
requires UnitOf<MP_UNITS_REMOVE_CONST(decltype(ToU)), Q::quantity_spec> &&
RepresentationOf<ToRep, Q::quantity_spec> && std::constructible_from<ToRep, typename Q::rep> &&
detail::ExplicitlyCastable<Q::unit, ToU, ToRep> &&
detail::ValidRoundingPolicyFor<Policy, typename Q::rep, ToRep>
[[nodiscard]]
constexpr
Quantity auto
value_cast(
FwdQ&& q,
Policy policy = Policy{});
Description
Implicit conversions between quantities of different types are allowed only for "safe" (e.g. non‐truncating) conversion. In truncating cases an explicit cast have to be used.
auto q = value_cast<int, us>(1.23 * ms);
Return Value
the quantity converted to unit ToU and representation type ToRep
|
Note
|
The return value should not be discarded. |
Template Parameters
Name |
Description |
ToRep |
a representation type to use for the target quantity |
ToU |
a unit to use for the target quantity |
Parameters
Name |
Description |
q |
the quantity to cast |
policy |
an optional rounding policy ( |
Created with MrDocs