[#mp_units-value_cast-0a] = xref:mp_units.adoc[mp_units]::value_cast :relfileprefix: ../ :mrdocs: Explicit cast of a quantity's representation == Synopsis Declared in `<mp‐units/framework/value_cast.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< xref:mp_units/Quantity.adoc[Quantity] ToQ, typename FwdQ, xref:mp_units/Quantity.adoc[Quantity] Q = std::remove_cvref_t<FwdQ>> requires (ToQ::quantity_spec == Q::quantity_spec) && (MP_UNITS_WEAK_UNIT_OF(MP_UNITS_NONCONST_TYPE(ToQ::unit), Q::quantity_spec)) && std::constructible_from<typename ToQ::rep, typename Q::rep> && detail::SaneScaling<Q::unit, ToQ::unit, typename ToQ::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. using ToQ = quantity<us, int>; auto q = value_cast<ToQ>(1.23 * ms); Note that value_cast only changes the "representation aspects" (unit and representation type), but not the "meaning" (quantity type). == Template Parameters [cols=2] |=== | Name | Description | *ToQ* | a target quantity type to which to cast the representation |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#