Skip to content

mp_units::Quantity

A concept matching every quantity

Synopsis

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

template<typename T>
concept Quantity = detail::is_derived_from_specialization_of_quantity<T>;

Description

Satisfied by every specialization of quantity and every type derived from one. Its counterpart for points is QuantityPoint, and the two tell apart overloads that a delta and a point need to handle differently:

// one name for printing a temperature and a temperature difference
void print_temp(std::string_view title, QuantityPoint auto temp)
{
  std::cout << title << ": " << temp << " (" << temp.delta_from(si::absolute_zero).in(K)
            << " above absolute zero)\n";
}

void print_temp(std::string_view title, Quantity auto temp)
{
  std::cout << title << ": " << temp << " (" << temp.in(K) << ")\n";
}

void report()
{
  quantity_point today = point<deg_C>(19.);
  quantity_point tomorrow = point<deg_C>(21.);
  print_temp("tomorrow", tomorrow);        // tomorrow: 21 °C (294.15 K above absolute zero)
  print_temp("change", tomorrow - today);  // change: 2 °C (2 K)
}

See Also