template alias args

Manu turkeyman at gmail.com
Mon May 21 08:20:21 PDT 2012


So I keep finding myself in a situation where I need to use an alias
template arg, but what I actually want to alias is a MEMBER of some symbol,
or even a function local.

struct MyStruct
{
   int x;
}

template Thing(alias t)
{
  ...
}

MyStruct s;

Thing!(s); // this is fine
Thing!(s.x); // this doesn't work

This seems like it should work intuitively, I was very surprised when it
didn't. 's.x' can be resolved just as easily as 's' at compile time, but
Walter said 'alias' could only understand absolute symbols, not symbol +
offset.
Has anyone else run into this? What's the reason for the restriction?

I've also found I need to do this on a number of occasions: template
Thing(alias T...)
Ie, receive an unknown number of aliases... But that doesn't work either.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120521/1d280b9f/attachment.html>


More information about the Digitalmars-d mailing list