Literals, Factory Functions, and Type Aliases
The units library provides three complementary ways to construct and work with physical quantities: literal operators, factory functions, and type aliases.
Literal Operators
User-defined literal operators for all SI units with their prefixes. Considering all combinations of underlying types, prefixes, and units, there are more than 50,000 literals defined.
Factory Functions
Factory functions provide the same functionality as literal operators but with a function call syntax. They are named as plurals or descriptive names.
auto d = nin::centimetres(3.0); // 3 cm
auto t = nin::seconds(1.5); // 1.5 s
auto v = nin::metres_v<float>(2.0f); // 2 m as float
Common factory functions
| Function | Returns |
|---|---|
|
time (second) |
|
length (metre) |
|
mass (gram) |
|
electric current (ampere) |
|
temperature (kelvin) |
|
amount of substance (mole) |
|
luminous intensity (candela) |
|
derived SI units |
|
common time units |
|
angle units |
|
imperial length |
Type Aliases
For each physical quantity, the library provides template and concrete aliases.
Pattern
| Pattern | Example |
|---|---|
|
|
|
|
|
|
|
|
|
|
Common type aliases
| Alias | Unit | Dimension |
|---|---|---|
|
second |
T |
|
metre |
L |
|
kilogram |
M |
|
ampere |
I |
|
kelvin |
Θ |
|
mole |
N |
|
candela |
J |
|
radian |
(dimensionless) |
|
hertz |
T-1 |
|
newton |
M·L·T-2 |
|
pascal |
M·L-1·T-2 |
|
joule |
M·L2·T-2 |
|
watt |
M·L2·T-3 |
|
coulomb |
T·I |
|
volt |
M·L2·T-3·I-1 |