Skip to content

mp_units::implicitly_scalable

Customization point: whether a conversion between two quantity types is implicit

Synopsis

Declared in <mp-units/framework/value_cast.h>

template<Unit auto FromUnit, typename FromRep, Unit auto ToUnit, typename ToRep>
constexpr bool implicitly_scalable =
  treat_as_floating_point<ToRep> ||
  (!treat_as_floating_point<FromRep> && is_integral_scaling(FromUnit, ToUnit));

Description

true when converting a quantity<FromUnit, FromRep> to a quantity<ToUnit, ToRep> truncates nothing, which holds when ToRep is treated as floating-point (see treat_as_floating_point), or when neither type is and the ratio of the units is an integer, as from metres to millimetres. Any other conversion needs value_cast or a rounding policy.

A fixed-point decimal type with six fractional digits stores 1234 mm as 1.234 m exactly, but isn't floating-point, so the default asks for a cast. Specializing treat_as_floating_point for it would make the conversions implicit, but would also reject the rounded, rounded_down, and rounded_up policies. When all the conversions a program makes fit in six digits, this specialization makes them implicit instead:

class decimal;  // fixed-point, with six fractional digits

template<auto FromUnit, auto ToUnit>
constexpr bool mp_units::implicitly_scalable<FromUnit, decimal, ToUnit, decimal> = true;

Template Parameters

NameDescription
FromUnitthe unit converted from
FromRepthe representation type converted from
ToUnitthe unit converted to
ToRepthe representation type converted to

See Also