[#mp_units-quantity-01-2constructor-06a] = xref:mp_units.adoc[mp_units]::xref:mp_units/quantity-01.adoc[quantity]::quantity :relfileprefix: ../../ :mrdocs: Constructors == Synopses Declared in `<mp‐units/framework/quantity.h>` Default constructor. Leaves the numerical value default‐initialized. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- [[nodiscard]] xref:mp_units/quantity-01/2constructor-062.adoc[quantity]() = default; ---- [.small]#xref:mp_units/quantity-01/2constructor-062.adoc[_» more..._]# Converting constructor from another quantity that shares an equivalent unit. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< auto R2, typename Rep2> requires detail::QuantityConstructibleFrom<quantity, quantity<R2, Rep2>> && (equivalent(unit, get_unit(R2))) [[nodiscard]] constexpr explicit(!std::convertible_to<Rep2, rep> || !mp_units::implicitly_convertible(get_quantity_spec(R2), quantity_spec) || !mp_units::implicitly_scalable<get_unit(R2), Rep2, unit, rep>) xref:mp_units/quantity-01/2constructor-07.adoc[quantity](xref:mp_units/quantity-01.adoc[quantity<R2, Rep2>] const& q); ---- [.small]#xref:mp_units/quantity-01/2constructor-07.adoc[_» more..._]# Converting constructor from another quantity whose unit needs scaling to this one. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< auto R2, typename Rep2> requires detail::QuantityConstructibleFrom<quantity, quantity<R2, Rep2>> && (!equivalent(unit, get_unit(R2))) [[nodiscard]] constexpr explicit(!std::convertible_to<Rep2, rep> || !mp_units::implicitly_convertible(get_quantity_spec(R2), quantity_spec) || !mp_units::implicitly_scalable<get_unit(R2), Rep2, unit, rep>) xref:mp_units/quantity-01/2constructor-067.adoc[quantity](xref:mp_units/quantity-01.adoc[quantity<R2, Rep2>] const& q); ---- [.small]#xref:mp_units/quantity-01/2constructor-067.adoc[_» more..._]# Constructs a quantity directly from a numerical value, without an explicit reference. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- [[nodiscard]] constexpr explicit(!mp_units::implicitly_convertible(quantity_spec, dimensionless)) xref:mp_units/quantity-01/2constructor-0c.adoc[quantity](xref:mp_units/quantity-01/rep.adoc[rep] val) requires detail::ExplicitFromNumber<reference>; ---- [.small]#xref:mp_units/quantity-01/2constructor-0c.adoc[_» more..._]# Constructs a quantity from a value convertible to `rep`, without an explicit reference. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<typename Value> requires detail::ExplicitFromNumber<reference> && detail::RepConstructibleFrom<rep, Value> && (!std::convertible_to<Value, rep>) [[nodiscard]] constexpr explicit xref:mp_units/quantity-01/2constructor-09.adoc[quantity](Value val); ---- [.small]#xref:mp_units/quantity-01/2constructor-09.adoc[_» more..._]# Deleted overload that rejects truncating conversions when constructing without a reference. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<typename Value> requires detail::ExplicitFromNumber<reference> && (!detail::RepConstructibleFrom<rep, Value>) constexpr explicit(!std::convertible_to<Value, rep> || !mp_units::implicitly_convertible(quantity_spec, dimensionless)) xref:mp_units/quantity-01/2constructor-0f0.adoc[quantity](Value val) = delete; ---- [.small]#xref:mp_units/quantity-01/2constructor-0f0.adoc[_» more..._]# Constructs a quantity from an external quantity‐like type via `quantity_like_traits`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<xref:mp_units/QuantityLike.adoc[QuantityLike] Q> requires detail::QuantityConstructibleFrom<quantity, detail::quantity_like_type<Q>> [[nodiscard]] constexpr explicit(quantity_like_traits<Q>::explicit_import || !std::convertible_to<detail::quantity_like_type<Q>, quantity<R, Rep>>) xref:mp_units/quantity-01/2constructor-08.adoc[quantity](Q const& q); ---- [.small]#xref:mp_units/quantity-01/2constructor-08.adoc[_» more..._]# Constructs a quantity from a numerical value and a reference with an equivalent unit. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<xref:mp_units/Reference-0ba.adoc[Reference] R2> requires (equivalent(unit, get_unit(R2{}))) [[nodiscard]] constexpr xref:mp_units/quantity-01/2constructor-0f8.adoc[quantity]( xref:mp_units/quantity-01/rep.adoc[rep] val, R2 ref); ---- [.small]#xref:mp_units/quantity-01/2constructor-0f8.adoc[_» more..._]# Deleted overload that rejects truncating conversions of the numerical value. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< typename Value, xref:mp_units/Reference-0ba.adoc[Reference] R2> requires (equivalent(unit, get_unit(R2{}))) && (!detail::RepConstructibleFrom<rep, Value>) constexpr xref:mp_units/quantity-01/2constructor-0fc.adoc[quantity]( Value val, R2 ref) = delete; ---- [.small]#xref:mp_units/quantity-01/2constructor-0fc.adoc[_» more..._]# Constructs a quantity from a numerical value and a reference with a different unit. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< typename FwdValue, xref:mp_units/Reference-0ba.adoc[Reference] R2> requires (!equivalent(unit, get_unit(R2{}))) && detail::QuantityConstructibleFrom<quantity, quantity<R2{}, std::remove_cvref_t<FwdValue>>> [[nodiscard]] constexpr xref:mp_units/quantity-01/2constructor-0b.adoc[quantity]( FwdValue&& val, R2 ref); ---- [.small]#xref:mp_units/quantity-01/2constructor-0b.adoc[_» more..._]# == Parameters [cols="1,4"] |=== | Name| Description | *q* | the source quantity to convert from | *val* | the numerical value to store | *ref* | a reference whose unit is equivalent to `unit` |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#