alias and mixin
ketmar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Sep 1 04:19:07 PDT 2014
On Mon, 01 Sep 2014 10:57:41 +0000
evilrat via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
wrote:
and to check that ugly hackery:
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 {}
struct B {}
struct C {}
mixin makeAlias!("coolStruct", "MyStruct", A);
mixin makeAlias!("coolStruct1", "B", C);
void doSomething(coolStruct cs)
{
static if (!is(typeof(cs) == A)) static assert(0);
//.. do something with struct ..
}
void doSomething1(coolStruct1 cs)
{
static if (!is(typeof(cs) == B)) static assert(0);
//.. do something with struct ..
}
-------------- 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/49c2bdbb/attachment.sig>
More information about the Digitalmars-d-learn
mailing list