Skip to content

mp_units::QuantityOf

A concept matching all quantities of the provided property

Synopsis

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

template<typename Q, auto V>
concept QuantityOf =
  Quantity<Q> && ((QuantitySpec<decltype(V)> &&
                   ReferenceOf<decltype(Q::reference), V>) ||
                  (detail::CharacterValue<V> && requires {
                    requires QuantitySpecOf<decltype(Q::quantity_spec), V> &&
                               RepresentationOf<typename Q::rep, V>;
                  }));

Description

V may be a quantity specification, in which case this is satisfied by all quantities with the reference satisfying ReferenceOf<V>, or a character (a bare quantity_tensor_order, a bare quantity_field, or a full quantity_character), in which case it is satisfied by all quantities whose specification admits that character and whose representation can fill it.

A scalar representation fills a vector or a tensor slot, a library rule generalizing clause 18 of ISO 80000-2:2019 (a scalar is a tensor of order zero, a vector one of order one). So a 1D velocity stored in a double is a vector quantity, and a quantity kind stored in a double matches every order. The specification side stays exact, so an isq::speed is never a vector quantity.

The type of V selects the reading: a specification asks only the quantity-tree question, and a character only the character question.

// the library's own signature example: an interface that names the quantities it takes
constexpr QuantityOf<isq::speed> auto avg_speed(QuantityOf<isq::length> auto distance,
                                                QuantityOf<isq::duration> auto duration)
{
  return distance / duration;
}

constexpr quantity speed = avg_speed(220. * km, 2. * h);  // 110 km/h
// doesn't compile: the arguments are swapped
// auto bad = avg_speed(2. * h, 220. * km);

See Also