International System of Units (SI) units and prefixes for use with std.units.
Possible string representations of units.
Shordhand for creating a basic unit with a name and a symbol, and no conversions defined.
An affine unit – the most common case being a unit that is related to other units representing the same physical quantity not by a scale factor, but by a shift in the zero point.
Converts a quantity to another unit.
Checks whether a quantity is convertible to a certain unit.
Raises a unit instance to a given power.
Raises a quantity to a given power.
A special unit used to represent dimensionless quantities.
Mixin template for creating prefix functions for all the prefixes in a prefix system. See PrefixedUnit and prefixTemplate.
Mixin template containing the implementation of the unit instance operators.
An affine unit – the most common case being a unit that is related to other units representing the same physical quantity not by a scale factor, but by a shift in the zero point.
Shordhand for creating a basic unit with a name and a symbol, and no conversions defined.
A pair of a (base) unit and a compile-time rational exponent.
A conversion »link« to a target unit, consisting of a callable converting a value to the target, and one for converting it back.
A special unit used to represent dimensionless quantities.
A named prefix, part of a PrefixSystem.
A unit with a scaling prefix applied, e.g. kilo(metre).
A quantity consisting of a value and an associated unit of measurement.
Shorthands for defining base units with a single conversion factor to another base unit.
An affine unit – the most common case being a unit that is related to other units representing the same physical quantity not by a scale factor, but by a shift in the zero point.
A conversion »link« to a target unit, consisting of a callable converting a value to the target, and one for converting it back.
Constructs a derived unit, consisting of a number of base units and associated exponents.
The difference between two compile-time rational numbers.
A prefix system, used with PrefixedUnit.
A unit with a scaling prefix applied, e.g. kilo(metre).
The product of two compile-time rational numbers.
A quantity consisting of a value and an associated unit of measurement.
A compile-time rational number.
Shorthands for defining base units with a single conversion factor to another base unit.
The sum of two compile-time rational numbers.
Shorthand for defining prefix templates like kilo!().
Shorthands for defining base units with a single conversion factor to another base unit.
enum foo = baseUnit!("foo", "f"); enum bar = scale!(foo, 21, "bar", "b"); auto a = 2 * bar; assert(convert!foo(a) == 42 * foo);
Todo:
Type-based, i.e. statically checked, units of measurement.
A quantity is a wrapper struct around an arbitrary value type, parametrized with a certain unit. A unit is basically little more than a marker type to keep different kinds of quantities apart, but might additionally have an associated name and symbol string, and – more more importantly – define conversions to other units. While all of the possible conversions must be defined statically for type-checking, arbitrary callables are supported for actually converting the values, which do not necessarily need to be evauatable at compile time.
Conversions only happen if explicitly requested and there is no different internal representation of values – for example 1 * kilo(metre) is stored just as 1 in memory, not as 1000 or relative to any other »canonical unit«.
On top of the template core of the module, to which units are types only, a layer making use of »dummy« unit instances with operators defined on them makes it possible to work with quantities and units in a natural way, such that the actual unit types never need to be user directly in client code (see the example below).
In the design of this module, the explicit concept of dimensions does not appear, because it would add a fair amount of complication to both the interface and the implementation for little benefit. Rather, the notion is established implicitly by defining conversions between pairs of units – to see if two units share the same dimension, just check for convertibility.
The std.si module defines SI prefixes and units for use with this module.