Skip to content

mp_units::subkind

Makes a quantity a kind of its own within the tree of its parent

Synopsis

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

struct subkind;

Description

The quantity keeps the dimension and units of its parent, but doesn't add to, compare with, or implicitly convert to any other quantity of its parent's kind, the parent included. A quantity of the parent's kind, such as 10 * one, converts to it only explicitly. That keeps apart quantities measured in the same unit that must not be mixed:

// both count pixels, but a horizontal count added to a vertical one is a bug
inline constexpr struct pixel_x : quantity_spec<dimensionless, subkind> {} pixel_x;
inline constexpr struct pixel_y : quantity_spec<dimensionless, subkind> {} pixel_y;

quantity left = pixel_x(10 * one);
quantity top = pixel_y(20 * one);
// doesn't compile: different kinds
// auto bad = left + top;

A quantity defined with it is a valid argument of kind_of.

See Also