mp_units::reference_for¶
The reference of a quantity type, or of a type that quantity_like_traits or quantity_point_like_traits describes
Synopsis¶
Declared in <mp-units/framework/quantity_traits.h>
template<typename T>
constexpr auto reference_for = detail::reference_for_impl<T>::value;
Description¶
It carries the quantity specification as well as the unit, so a value built with it has the caller's quantity specification, such as isq::height, and not only its unit:
// a sensor reading, delivered as a raw number in the units the caller's type uses
template<typename Q>
Q from_register(std::int32_t raw)
{
return Q(static_cast<rep_for<Q>>(raw) * reference_for<Q>);
}
auto delay = from_register<std::chrono::milliseconds>(1500); // 1500 ms
auto height = from_register<quantity<isq::height[mm], int>>(1500); // 1500 mm
It isn't a customization point. A type is described by specializing quantity_like_traits or quantity_point_like_traits.
Template Parameters¶
| Name | Description |
|---|---|
| T | a quantity or quantity point type, or a type that either trait describes |
See Also¶
unit_forfor the unit alonerep_forfor the representation type- Converting External Quantity Types