Skip to content

mp_units::ReferenceOf

A concept matching the references of a given quantity

Synopsis

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

template<typename T, auto QS>
concept ReferenceOf =
  Reference<T> && QuantitySpecOf<decltype(get_quantity_spec(T{})), QS>;

Description

Satisfied by a Reference whose quantity specification satisfies QuantitySpecOf with QS, so QS may also be a character. isq::height[si::metre] and si::metre are references of isq::length, while isq::length[si::metre] is not a reference of isq::height.

// a field bus delivers raw integers, and the protocol says what each one means
template<ReferenceOf<isq::length> auto R>
constexpr quantity<R, std::int32_t> decode_length(std::int32_t raw) { return raw * R; }

constexpr quantity height = decode_length<isq::height[mm]>(1500);  // 1500 mm
// doesn't compile: not a length
// auto bad = decode_length<isq::duration[ms]>(1500);
// values of types nobody spells, so naming what each one is and which quantity it belongs to
// helps where `auto` alone doesn't
constexpr QuantitySpecOf<isq::power> auto power_spec = isq::energy / isq::duration;
constexpr UnitOf<isq::power> auto power_unit = si::joule / si::second;
constexpr ReferenceOf<isq::power> auto power_reference = power_spec[power_unit];

See Also