Skip to content

Dimensional refinement

"I mean, it's sort of exciting, isn't it, breaking the rules?" — Hermione Granger, Harry Potter and the Order of the Phoenix


Defined in header <dimensional/refinement.hpp>.

Refinement type

A function that can be guaranteed at compile time to have dimensions in accordance with the purpose while inferring units of quantity type.

The following is a compilation error if the quantity (2 | meters) * (7 | meters) does not have the dimension of area completely. This code can be compiled through refinement, since is of dimension .

quantity_t a1 = accepts<area_r> |= (2|meters) * (7|meters);

If you want to specify the unit should be written as follows. The difference is that automatic unit conversion is performed when units are different. accepts examines only the dimensions, not the units.

quantity<meter_t, int> a1 = (2|meters) * (7|meters);

The following example does not compile. This is because is the dimension of and not .

quantity_t a3 = accepts<area_r> |= (2|millimeters); // error!

Partial refinement type

The following is a compilation error if the quantity (2 | meters) * (2 | meters) * (2 | kilograms) / (2 | second <2>) does not partially have the dimension of mass . The compilation passes because it actually has.

quantity_t a3
    = partial_accepts<sym::M<>>
    |= (2|meters) * (2|meters) * (2|kilograms) / (2|second<2>);