DefinePrefixSystem

Mixin template for creating prefix functions for all the prefixes in a prefix system. See PrefixedUnit and prefixTemplate.

@safe
mixin template DefinePrefixSystem (
alias System
)

Examples

mixin DefinePrefixSystem!(PrefixSystem!(10, { return [
    Prefix(-3, "milli", "m"),
    Prefix(3, "kilo", "k")
]; });
// Use milli!() and kilo!() as usual.
alias System = PrefixSystem!(10, { return [Prefix(-6, "micro", "µ"), Prefix(-3, "milli", "m"), Prefix(3, "kilo", "k")]; });

alias kilo = prefixTemplate!(3, System);
alias milli = prefixTemplate!(-3, System);

// FIXME: For reasons unknown, PrefixedUnit.toString() isn't CTFEable.
enum kilofoo = kilo!foo;
assert(kilofoo.toString() == "kilofoo");
assert(kilofoo.toString(UnitString.symbol) == "kf");

static assert(is(typeof(milli!(kilo!foo)) == Foo));

enum microfoo = milli!(milli!foo);
assert(microfoo.toString() == "microfoo");
assert(microfoo.toString(UnitString.symbol) == "µf");

static assert(!__traits(compiles, kilo(kilo(foo))),
    "Requesting a prefix not in the table didn't fail.");

assert(convert!Foo(1 * kilo!foo) == 1000 * foo);

enum millifoobar = milli!(foo * bar);
assert(millifoobar.toString() == "milli<bar foo>");
assert(millifoobar.toString(UnitString.symbol) == "m<br f>");

Meta