[#mp_units-value_cast-0f] = xref:mp_units.adoc[mp_units]::value_cast :relfileprefix: ../ :mrdocs: Explicit cast of a quantity's unit == Synopsis Declared in `<mp‐units/framework/value_cast.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< auto ToU, typename FwdQ, xref:mp_units/Quantity.adoc[Quantity] Q = std::remove_cvref_t<FwdQ>> requires UnitOf<MP_UNITS_REMOVE_CONST(decltype(ToU)), Q::quantity_spec> && detail::SaneScaling<Q::unit, ToU, typename Q::rep> [[nodiscard]] constexpr xref:mp_units/Quantity.adoc[Quantity] auto value_cast(FwdQ&& q); ---- == 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 d = value_cast<si::second>(1234 * ms); == Template Parameters [cols="1,4"] |=== |Name|Description | *ToU* | a unit to use for a target quantity |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#