mp_units::QuantitySpecOf¶
A concept matching the quantity specifications that convert to a given one or admit a given character
Synopsis¶
Declared in <mp-units/framework/quantity_spec_concepts.h>
template<typename T, auto V>
concept QuantitySpecOf =
QuantitySpec<T> &&
((QuantitySpec<decltype(V)> &&
mp_units::utility::implicitly_convertible(T{}, V)) ||
(detail::CharacterValue<V> &&
detail::overlaps(T::_character_.order, detail::axis_mask<V>().order) &&
detail::overlaps(T::_character_.field, detail::axis_mask<V>().field)));
Description¶
V may be another quantity specification, in which case this is satisfied by every specification implicitly convertible to it, or a character (a bare quantity_tensor_order, a bare quantity_field, or a full quantity_character), in which case it is satisfied by every specification that admits that character. A quantity kind admits every character. As in QuantityOf, the type of V selects the reading.
Ask this where no quantity exists yet to ask QuantityOf about, such as constraining a reference taken as a template parameter (utility::polar_vector requires a radius whose specification admits scalar).
// a gauge reports a magnitude, never a direction
template<QuantitySpecOf<quantity_tensor_order::scalar> auto QS>
struct gauge_reading {
quantity<QS[mm], double> value;
};
constexpr gauge_reading<isq::thickness> coating{isq::thickness(0.25 * mm)};
// doesn't compile; unconstrained, it would accept a vector quantity, as a scalar may store one
// gauge_reading<isq::displacement> bad;
// 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¶
- Concepts in the User's Guide