Tuple/Typedef question
Dicebot via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jan 11 04:44:45 PST 2015
I use this Typedef implementation instead:
/// one with non-default initializer
template Typedef(T, istring name, T initval)
{
static assert (name.length, "Can't create Typedef with an
empty identifier");
enum Typedef =
("struct " ~ name ~
"{ " ~
T.stringof ~ " value = " ~ initval.stringof ~ ";"
~
"alias value this;" ~
" }");
}
/// basic overload
template Typedef(T, istring name)
{
static assert (name.length, "Can't create Typedef with an
empty identifier");
enum Typedef =
("struct " ~ name ~
"{ " ~
T.stringof ~ " value; " ~
"alias value this;" ~
" }");
}
unittest
{
mixin(Typedef!(int, "MyInt1"));
mixin(Typedef!(int, "MyInt2"));
static assert (!is(MyInt1 : MyInt2));
}
More information about the Digitalmars-d-learn
mailing list