smjg.libs.util.dimval

This module is used to perform arithmetic on physical measurements (length, time, etc.) with compile-time checking that the values combined are of compatible dimensions.

Since:
0.10
template isDimensionedValue(T)

Detects whether T is a DimensionedValue.

struct DimensionedValue(Base,Dims...) if (Dims.length != 0 && !isDimensionedValue!(Base) && CheckDim!(Dims));

The DimensionedValue struct template is used to declare a value that represents a physical measurement and therefore has dimensions such as length, time, etc.

Dimensions correspond to multiplicatively independent measurements. Which dimensions correspond to which measurements is left up to the application. It is the application's responsibility to ensure that a given dimension is always measured in the same units.

Arithmetic and comparison operations are implemented in terms of those of the base types, and the the base type of the returned value determined accordingly. They are allowed according to the following table:

Operator Allowed dimensions Returned dimensions
+, -, % Same Same
*, / Any Combined
+=, -=, %= Same Same
*=, /= Dimensionless Same
==, !=, <, <=, >, >= Same Dimensionless (just a boolean)
Params:
Base the base type, in which the actual value of the measurement is stored.
Dims exponents of zero or more further dimensions (must be of type int).
Preconditions:
The final given dimension must not be 0. (Just leave it off.)
Example:
Suppose the first dimension is length, and the second dimension is time.
DimensionedValue!(real, 1)     length;
DimensionedValue!(real, 2)     area;
DimensionedValue!(real, 0,  1) time;
DimensionedValue!(real, 1, -1) speed;
DimensionedValue!(real, 1, -2) acceleration;
Base value;

The value of the measurement.

this()(in BaseType v);

Constructs a DimensionedValue that holds the value v.

this(T : DimensionedValue!(U,Dims), U)(in T v);

Constructs a DimensionedValue from another of the same dimensions and a base type implicitly convertible to the base type of this one.

template MulType(T)

The type of a DimensionedValue of this type multiplied by a T.

BUGS:
As of DMD 2.058, it doesn't work through an alias of the DimensionedValue type (issue 7447)
template DivType(T)

The type of a DimensionedValue of this type divided by a T.

BUGS:
As of DMD 2.058, it doesn't work through an alias of the DimensionedValue type (issue 7447)
alias InvType;

The reciprocal type to this DimensionedValue.

template DivRType(T)

The type of a T divided by a DimensionedValue of this type.