Skip to content

mp_units::RepresentationOf

A concept matching the types that can store the numerical value of a given quantity

Synopsis

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

template<typename T, auto V>
concept RepresentationOf =
  detail::representation_enabled<T> && detail::SomeRepresentation<T> &&
  detail::CharacterConstraint<V> &&
  requires { requires detail::CharacterAdmitted<T, V>; };

Description

Satisfied by a representation type whose character the quantity specification or character V admits. The field has to match exactly, and a lower order may stand in for a higher one: double represents both speed and velocity, while std::complex<double> represents neither.

// a weather record whose fields all use the numeric type the station reports in
template<RepresentationOf<quantity_field::real> Rep>
struct weather_record {
  quantity<isq::thermodynamic_temperature[K], Rep> temperature;
  quantity<isq::pressure[Pa], Rep> pressure;
  quantity<isq::speed[m / s], Rep> wind_speed;
};

weather_record<float> compact;
weather_record<double> precise;
// doesn't compile: the fields are real quantities
// weather_record<std::complex<double>> bad;

See Also