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

Explicit cast of a quantity&apos;s unit

== 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;
    auto ToU,
    typename FwdQ,
    xref:mp_units/Quantity.adoc[Quantity] Q = std::remove&lowbar;cvref&lowbar;t&lt;FwdQ&gt;&gt;
requires UnitOf&lt;MP&lowbar;UNITS&lowbar;REMOVE&lowbar;CONST(decltype(ToU)), Q&colon;&colon;quantity&lowbar;spec&gt; &amp;&amp;
           detail&colon;&colon;ExplicitlyCastable&lt;Q&colon;&colon;unit, ToU, typename Q&colon;&colon;rep&gt;
&lsqb;&lsqb;nodiscard&rsqb;&rsqb;
constexpr
xref:mp_units/Quantity.adoc[Quantity] auto
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 d &equals; value&lowbar;cast&lt;si&colon;&colon;second&gt;(1234 &ast; ms)&semi;

== Return Value

[NOTE]
====
The return value https://en.cppreference.com/cpp/language/attributes/nodiscard[should not be discarded^].
====
== Template Parameters

[cols="1,4"]
|===
| Name| Description
| *ToU*
| a unit to use for a target quantity
|===


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