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

1 mixin DefinePrefixSystem!(PrefixSystem!(10, { return [
2    Prefix(-3, "milli", "m"),
3    Prefix(3, "kilo", "k")
4 ]; });
5 // Use milli!() and kilo!() as usual.
1 alias System = PrefixSystem!(10, { return [Prefix(-6, "micro", "µ"), Prefix(-3, "milli", "m"), Prefix(3, "kilo", "k")]; });
2 
3 alias kilo = prefixTemplate!(3, System);
4 alias milli = prefixTemplate!(-3, System);
5 
6 // FIXME: For reasons unknown, PrefixedUnit.toString() isn't CTFEable.
7 enum kilofoo = kilo!foo;
8 assert(kilofoo.toString() == "kilofoo");
9 assert(kilofoo.toString(UnitString.symbol) == "kf");
10 
11 static assert(is(typeof(milli!(kilo!foo)) == Foo));
12 
13 enum microfoo = milli!(milli!foo);
14 assert(microfoo.toString() == "microfoo");
15 assert(microfoo.toString(UnitString.symbol) == "µf");
16 
17 static assert(!__traits(compiles, kilo(kilo(foo))),
18     "Requesting a prefix not in the table didn't fail.");
19 
20 assert(convert!Foo(1 * kilo!foo) == 1000 * foo);
21 
22 enum millifoobar = milli!(foo * bar);
23 assert(millifoobar.toString() == "milli<bar foo>");
24 assert(millifoobar.toString(UnitString.symbol) == "m<br f>");

Meta