DerivedUnit

Constructs a derived unit, consisting of a number of base units and associated exponents.

Usually, constructing unit types using the operators defined on the unit instances is preferred over using this template directly.

Internally, derived units are represented as DUnit instances, but never try to use it directly – the DerivedUnit template performs canonicalization to ensure that semantically equivalent units share the same underlying types. Also, the result will not actually be a DUnit in some cases, but rather Dimensionless or a single base unit without exponent.

  1. template DerivedUnit(T...)
    @safe
    template DerivedUnit (
    T...
    ) if (
    allSatisfy!(isBaseUnitExp, T)
    ) {}
  2. struct DUnit(T...)

Members

Aliases

DerivedUnit
alias DerivedUnit = MakeDerivedUnit!(T).Result
Undocumented in source.

Examples

alias Coulomb = DerivedUnit!(
    BaseUnitExp!(Ampere, Rational!1),
    BaseUnitExp!(Second, Rational!1));
enum coulomb = Coulomb.init;

// In most cases, you would want to just use the operators
// on the unit instances instead:
enum coulomb = ampere * second;
alias A = DerivedUnit!(BaseUnitExp!(Foo, Rational!(-2)));
static assert(is(A.BaseUnitExps == AliasSeq!(BaseUnitExp!(Foo,
    Rational!(-2)))), "Basic compound unit construction does not work.");

static assert(is(DerivedUnit!(BaseUnitExp!(Foo, Rational!2),
    BaseUnitExp!(Bar, Rational!1), BaseUnitExp!(Baz, Rational!3)) == DerivedUnit!(
    BaseUnitExp!(Bar, Rational!1), BaseUnitExp!(Baz, Rational!3),
    BaseUnitExp!(Foo, Rational!2))), "Base unit sorting does not work.");

// FIXME: Another problem probably related to signed/unsigned integer
// literals, uncomment BarBU-related arguments below to see the assert fail.
static assert(is(DerivedUnit!(BaseUnitExp!(Foo, Rational!2),
    BaseUnitExp!(Foo, Rational!1) /+,
        BaseUnitExp!(Bar, Rational!(-3)), BaseUnitExp!(Bar, Rational!2)+/
) == DerivedUnit!(BaseUnitExp!(Foo, Rational!3), /+BaseUnitExp!(Bar, Rational!(-1)+/
    )), "Base unit joining does not work.");

static assert(is(DerivedUnit!(BaseUnitExp!(Foo, Rational!2),
    BaseUnitExp!(Foo, Rational!(-2))) == Dimensionless),
    "Zero exponent base unit pruning does not work.");

static assert(is(DerivedUnit!(BaseUnitExp!(Dimensionless, Rational!1),
    BaseUnitExp!(Foo, Rational!1)) == Foo),
    "Removing Dimensionless during zero exponent pruning does not work.");

static assert(is(DerivedUnit!(BaseUnitExp!(Foo, Rational!1)) == Foo),
    "Demotion of trivial compound units to base units does not work.");

Meta