digitalmars.D - template alias args
- Manu <turkeyman gmail.com> May 21 2012
--20cf300fb283c531ac04c08d70e1
Content-Type: text/plain; charset=UTF-8
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.
--20cf300fb283c531ac04c08d70e1
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div>So I keep finding myself in a situation where I need to use an alias t=
emplate arg, but what I actually want to alias is a MEMBER of some symbol, =
or even a function local.</div><div><br></div><div>struct MyStruct</div>
<div>{</div><div>=C2=A0 =C2=A0int x;</div><div>}</div><div><br></div><div><=
div>template Thing(alias t)</div><div>{</div><div>=C2=A0 ...</div><div>}</d=
iv><br class=3D"Apple-interchange-newline"></div><div>MyStruct=C2=A0s;</div=
<div><br></div><div>
/div><div><br></div><div>This seems like it should work intuitively, I was =
very surprised when it didn't. 's.x' can be resolved just as ea=
sily as 's' at compile time, but Walter said 'alias' could =
only understand absolute symbols, not symbol + offset.</div>
<div>Has anyone else run into this? What's the reason for the restricti=
on?</div><div><br></div><div><div>I've also found I need to do this on =
a number of occasions: template Thing(alias T...)</div><div>Ie, receive an =
unknown number of aliases... But that doesn't work either.</div>
</div>
--20cf300fb283c531ac04c08d70e1--
May 21 2012








Manu <turkeyman gmail.com>