[#mp_units-value_cast-028]
= xref:mp_units.adoc[mp&lowbar;units]::value&lowbar;cast
:relfileprefix: ../
:mrdocs:

Explicit cast of a quantity&apos;s representation type

== Synopsis

Declared in `&lt;mp&hyphen;units&sol;framework&sol;value&lowbar;cast&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    typename ToRep,
    typename FwdQ,
    xref:mp_units/Quantity.adoc[Quantity] Q = std::remove&lowbar;cvref&lowbar;t&lt;FwdQ&gt;&gt;
requires RepresentationOf&lt;ToRep, Q&colon;&colon;quantity&lowbar;spec&gt; &amp;&amp; std&colon;&colon;constructible&lowbar;from&lt;ToRep, typename Q&colon;&colon;rep&gt;
&lsqb;&lsqb;nodiscard&rsqb;&rsqb;
constexpr
xref:mp_units/quantity-01.adoc[quantity&lt;Q&colon;&colon;reference, ToRep&gt;]
value&lowbar;cast(FwdQ&& q);
----

== Description

Implicit conversions between quantities of different types are allowed only for &quot;safe&quot; (e&period;g&period; non&hyphen;truncating) conversion&period; In truncating cases an explicit cast have to be used&period;

auto q &equals; value&lowbar;cast&lt;int&gt;(1&period;23 &ast; ms)&semi;

== Return Value

A quantity

== Template Parameters

[cols=2]
|===
| Name
| Description
| *ToRep*
| a representation type to use for a target quantity
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
