scale

Shorthands for defining base units with a single conversion factor to another base unit.

The conversion is done by simply multiplying/dividing the value by the passed factor, which thus has to be defined for all value types this scaled unit is used with.

Note that a generic alias is accepted as scaling factor, which makes it possible to use runtime values as scale factors without writing a custom unit type.

  1. struct ScaledUnit(BaseUnit, alias toBaseFactor, string name, string symbol = null)
  2. template ScaledUnit(alias baseUnit, alias toBaseFactor, string name, string symbol = null)
  3. template scale(alias baseUnit, alias toBaseFactor, string name, string symbol = null)
    @safe
    template scale (
    alias baseUnit
    alias toBaseFactor
    string name
    string symbol = null
    ) if (
    isUnitInstance!baseUnit
    ) {}

Members

Manifest constants

scale
enum scale;
Undocumented in source.

Examples

// The following three lines define the same unit. Most of the time, the
// third syntax is the preferred one because it directly declares a unit
// instance.
alias ScaledUnit!(Metre, 0.0254, "inch", "in") Inch;
alias ScaledUnit!(metre, 0.0254, "inch", "in") Inch;
enum inch = scale!(metre, 0.0254, "inch", "in");

Meta