[#mp_units-quantity_cast-07] = xref:mp_units.adoc[mp_units]::quantity_cast :relfileprefix: ../ :mrdocs: Explicit cast of a quantity type == Synopsis Declared in `<mp‐units/framework/quantity_cast.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< xref:mp_units/QuantitySpec.adoc[QuantitySpec] auto ToQS, typename FwdQ, xref:mp_units/Quantity.adoc[Quantity] Q = std::remove_cvref_t<FwdQ>> requires (castable(Q::quantity_spec, ToQS)) && requires { typename quantity<make_reference(ToQS, Q::unit), typename Q::rep>; } [[nodiscard]] constexpr xref:mp_units/Quantity.adoc[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: [,cpp] ---- {.cpp} auto length = isq::length(42 * m); auto distance = quantity_cast(length); ---- [NOTE] ==== This cast does not affect the underlying value of a number stored in a quantity. ==== == Template Parameters [cols="1,4"] |=== |Name|Description | *ToQS* | a quantity specification to use for a target quantity |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#