[#mp_units-value_cast-035] = xref:mp_units.adoc[mp_units]::value_cast :relfileprefix: ../ :mrdocs: Explicit cast of a quantity point'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 FwdQP, xref:mp_units/QuantityPoint.adoc[QuantityPoint] QP = std::remove_cvref_t<FwdQP>> requires (ToQ::quantity_spec == QP::quantity_spec) && (MP_UNITS_WEAK_UNIT_OF(MP_UNITS_NONCONST_TYPE(ToQ::unit), QP::quantity_spec)) && std::constructible_from<typename ToQ::rep, typename QP::rep> && detail::SaneScaling<QP::unit, ToQ::unit, typename ToQ::rep> [[nodiscard]] constexpr xref:mp_units/QuantityPoint.adoc[QuantityPoint] auto value_cast(FwdQP&& qp); ---- == 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. inline constexpr struct A : absolute_point_origin[ A;] using ToQ = quantity<mm, int>; auto qp = value_cast<ToQ>(quantity_point{1.23 * m}); Note that value_cast only changes the "representation aspects" (unit and representation type), but not the "meaning" (quantity type or the actual point that is being described). == Template Parameters [cols=2] |=== | Name | Description | *ToQ* | a target quantity type to which to cast the representation of the point |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#