mp_units::unit_for¶
The unit 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 unit_for = detail::unit_for_impl<T>::value;
Description¶
Generic code uses it to produce a value in whatever type its caller uses, std::chrono or mp-units:
template<typename Duration>
Duration eta(QuantityOf<isq::distance> auto remaining, QuantityOf<isq::speed> auto speed)
{
return Duration(value_cast<rep_for<Duration>, unit_for<Duration>>(remaining / speed));
}
auto chrono_eta = eta<std::chrono::minutes>(isq::distance(50. * km), isq::speed(100. * km / h));
auto quantity_eta = eta<quantity<min, int>>(isq::distance(50. * km), isq::speed(100. * km / h));
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¶
reference_forfor the quantity specification together with the unitrep_forfor the representation type- Converting External Quantity Types