struct ConvertibleToFoo
{
mixin UnitImpl;
alias Conversions = AliasSeq!(Conversion!(Foo, toFoo, fromFoo));
static string toString(UnitString type = UnitString.name)
{
final switch (type)
{
case UnitString.name:
return "convertibleToFoo";
case UnitString.symbol:
return "ctf";
}
}
static V toFoo(V)(V v)
{
return v * 3;
}
static V fromFoo(V)(V v)
{
return v / 3;
}
}
enum convertibleToFoo = ConvertibleToFoo.init;
// »Regular« conversion.
auto c = 2 * convertibleToFoo;
assert(c.convert!foo == 6 * foo);
// »Inverse« conversion.
auto f = 9 * foo;
assert(f.convert!convertibleToFoo == 3 * convertibleToFoo);
static assert((2 * convertibleToFoo).isConvertibleTo!foo);
static assert(!(2 * convertibleToFoo).isConvertibleTo!bar);
Checks whether a quantity is convertible to a certain unit.