www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - How to alias for identity

reply "Martin Nowak" <dawg dawgfoto.de> writes:
I was using some templates to declare different parameters sets.

template unitA() {...}
template unitB() {...}
template unitC() {...}

I have a generic function that is parameterized by these units.
void foo(alias unit) {...}

Now unitA gets a specialization.

void foo(alias unit:unitA!()) {}

But here I'm a little stuck because this won't work in my case due to a  
bug (there are more parameters).
http://d.puremagic.com/issues/show_bug.cgi?id=6701

Does anybody know of a way to test an alias for identity.

void foo(alias unit) if(unit == unitA!()) {} // won't work of course

martin
Oct 26 2011
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 10/26/2011 09:41 PM, Martin Nowak wrote:
 I was using some templates to declare different parameters sets.

 template unitA() {...}
 template unitB() {...}
 template unitC() {...}

 I have a generic function that is parameterized by these units.
 void foo(alias unit) {...}

 Now unitA gets a specialization.

 void foo(alias unit:unitA!()) {}

 But here I'm a little stuck because this won't work in my case due to a
 bug (there are more parameters).
 http://d.puremagic.com/issues/show_bug.cgi?id=6701

 Does anybody know of a way to test an alias for identity.

 void foo(alias unit) if(unit == unitA!()) {} // won't work of course

 martin
This will do the job: void foo(alias unit)() if(unit.mangleof == unitA!().mangleof) {}
Oct 26 2011
parent "Martin Nowak" <dawg dawgfoto.de> writes:
On Wed, 26 Oct 2011 22:18:29 +0200, Timon Gehr <timon.gehr gmx.ch> wrote:

 On 10/26/2011 09:41 PM, Martin Nowak wrote:
 I was using some templates to declare different parameters sets.

 template unitA() {...}
 template unitB() {...}
 template unitC() {...}

 I have a generic function that is parameterized by these units.
 void foo(alias unit) {...}

 Now unitA gets a specialization.

 void foo(alias unit:unitA!()) {}

 But here I'm a little stuck because this won't work in my case due to a
 bug (there are more parameters).
 http://d.puremagic.com/issues/show_bug.cgi?id=6701

 Does anybody know of a way to test an alias for identity.

 void foo(alias unit) if(unit == unitA!()) {} // won't work of course

 martin
This will do the job: void foo(alias unit)() if(unit.mangleof == unitA!().mangleof) {}
Thanks, better than the .stringof I resorted to.
Oct 28 2011