On 01.04.2016 01:58, Nordlöw wrote:
https://github.com/nordlow/units-d
From there:
* Example:
* ---
* alias BaseUnit!("Ampere", "A") Ampere;
* enum ampere = Ampere.init;
* // or
* enum ampere = baseUnit!("Ampere", "A");
* ---
I dislike that the type depends only on the given name. This effectively
means that the names are in a global namespace.
For example:
----
import experimental.units;
struct A
{
alias BaseUnit!("Ampere", "A") Ampere;
enum ampere = Ampere.init;
}
struct B
{
alias BaseUnit!("Ampere", "A") Ampere;
enum ampere = Ampere.init;
}
----
A.Ampere and B.Ampere are the same type here. I think it would be more
useful if they weren't. When two unrelated sources define a new unit
with the same name, then they shouldn't be compatible. Think of all the
different kinds of pounds and miles there used to be in the world.
I can't think of a truly nice way to accomplish this, though. As far as
I see, it needs a mixin of some kind.
Like this, for example:
----
enum string baseUnit = q{
{
static struct BaseUnit {/* ... */}
return BaseUnit.init;
}()
};
struct A
{
enum ampere = mixin(baseUnit);
}
struct B
{
enum ampere = mixin(baseUnit);
}
static assert(!is(typeof(A.ampere) == typeof(B.ampere)));
----