Aliasing of template results
Alex Rønne Petersen
xtzgzorex at gmail.com
Sun Jan 22 06:51:35 PST 2012
Hi,
Someone on IRC wanted to know the element type of an array type and the
following code was suggsted:
template ElementType(T : T[])
{
alias T ElementType;
}
He was confused about how ElementType!(int[]) could possibly equal int,
until we explained that the alias does, in fact, represent the 'result'
of the template.
So we started discussing whether a more intuitive syntax could be found.
Someone suggsted:
template ElementType(T : T[])
{
alias T template;
}
I personally believe this makes it perfectly clear that you're aliasing
the template itself to T.
Thoughts?
--
- Alex
More information about the Digitalmars-d
mailing list