mp_units::rep_for¶
The representation type 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>
using rep_for = /* implementation-defined */ ::type;
Description¶
Generic code can branch on it, for example to round up into an integral tick count:
template<typename Duration>
Duration timeout(QuantityOf<isq::duration> auto requested)
{
// an integral tick count rounds up, so the wait is never shorter than requested
if constexpr (treat_as_floating_point<rep_for<Duration>>)
return Duration(value_cast<rep_for<Duration>, unit_for<Duration>>(requested));
else
return Duration(value_cast<rep_for<Duration>>(ceil<unit_for<Duration>>(requested)));
}
auto whole = timeout<std::chrono::milliseconds>(1.2345 * s); // 1235 ms
auto exact = timeout<std::chrono::duration<double, std::milli>>(1.2345 * s); // 1234.5 ms
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 alonereference_forfor the quantity specification together with the unit- Converting External Quantity Types