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

Explicit cast of a quantity point&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;
    xref:mp_units/Unit.adoc[Unit] auto ToU,
    typename FwdQP,
    xref:mp_units/RoundingPolicy.adoc[RoundingPolicy] Policy = xref:mp_units/truncated_t.adoc[truncated&lowbar;t],
    xref:mp_units/QuantityPoint.adoc[QuantityPoint] QP = std::remove&lowbar;cvref&lowbar;t&lt;FwdQP&gt;&gt;
requires UnitOf&lt;MP&lowbar;UNITS&lowbar;REMOVE&lowbar;CONST(decltype(ToU)), QP&colon;&colon;quantity&lowbar;spec&gt; &amp;&amp;
           detail&colon;&colon;ExplicitlyCastable&lt;QP&colon;&colon;unit, ToU, typename QP&colon;&colon;rep&gt; &amp;&amp;
           detail&colon;&colon;ValidRoundingPolicyFor&lt;Policy, typename QP&colon;&colon;rep, typename QP&colon;&colon;rep&gt;
&lsqb;&lsqb;nodiscard&rsqb;&rsqb;
constexpr
xref:mp_units/QuantityPoint.adoc[QuantityPoint] auto
value&lowbar;cast(
    FwdQP&& qp,
    Policy policy = Policy&lcub;&rcub;);
----

== Description

Implicit conversions between quantity points 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 qp &equals; value&lowbar;cast&lt;si&colon;&colon;second&gt;(quantity&lowbar;point&lcub;1234 &ast; ms&rcub;)&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 point
|===

== Parameters

[cols="1,4"]
|===
| Name| Description
| *policy*
| an optional rounding policy (`truncated` when not provided)
|===


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