Skip to content

mp_units::PrefixableUnit

A concept matching the units that prefixed_unit accepts

Synopsis

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

template<typename T>
concept PrefixableUnit = Unit<T> && is_derived_from_specialization_of_v<T, named_unit>;

Description

Satisfied by a unit derived from named_unit, such as si::metre or si::gram. A prefixed unit, such as si::kilogram, and an unnamed derived unit, such as si::metre / si::second, don't satisfy it. The concept doesn't encode which prefixes a system's conventions allow, so si::kilo<si::hour> compiles, although the SI doesn't prefix the hour.

// a prefix of 10⁴ that the SI doesn't define, declared the way the SI prefixes are
template<PrefixableUnit U>
struct myria_ final : prefixed_unit<"my", mag_power<10, 4>, U{}> {};

template<PrefixableUnit auto U>
constexpr myria_<decltype(U)> myria;

constexpr quantity distance = 1 * myria<si::metre>;  // 1 mym, the same as 10 km
// doesn't compile: the kilogram already has a prefix
// auto bad = myria<si::kilogram>;

See Also