alias and mixin
ketmar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Sep 1 04:14:06 PDT 2014
On Mon, 01 Sep 2014 10:57:41 +0000
evilrat via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
wrote:
here's some more ugly hackery for you:
string makeAlias(string aliasName, string Name, alias Replace) ()
{
static if ( __traits(compiles, (mixin(Name~`.sizeof`))) )
return `alias `~aliasName~` = ` ~ Name ~ `;`;
static if ( (is(Replace == class) || is(Replace == struct)) )
return `alias `~aliasName~` = ` ~ Replace.stringof ~ `;`;
assert(0);
}
struct A {}
mixin(makeAlias!("coolStruct", "MyStruct", A));
or:
mixin template makeAlias(string aliasName, string Name, alias Replace)
{
static if ( __traits(compiles, (mixin(Name~`.sizeof`))) )
mixin(`alias `~aliasName~` = ` ~ Name ~ `;`);
static if ( (is(Replace == class) || is(Replace == struct)) )
mixin(`alias `~aliasName~` = ` ~ Replace.stringof ~ `;`);
else static assert(0);
}
struct A {}
mixin makeAlias!("coolStruct", "MyStruct", A);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20140901/40c35174/attachment.sig>
More information about the Digitalmars-d-learn
mailing list