Question about eponymous template trick
MrSmith via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Nov 3 06:22:59 PST 2014
On Monday, 3 November 2014 at 14:07:55 UTC, Uranuz wrote:
> I have an example of code like this:
>
> template Node(String)
> {
> struct Node {}
> struct Name {}
> struct Attr {}
>
> }
>
> void main()
> {
> alias MyNode = Node!(string).Node;
> alias MyName = Node!(string).Name;
> alias MyAttr = Node!(string).Attr;
>
> }
>
> This code fails during compilation with message:
>
> Compilation output:
>
> /d228/f410.d(12): Error: no property 'Node' for type
> 'Node!string' /d228/f410.d(12): Error: no property 'Node' for
> type 'Node!string' /d228/f410.d(13): Error: no property 'Name'
> for type 'Node!string' /d228/f410.d(13): Error: no property
> 'Name' for type 'Node!string' /d228/f410.d(14): Error: no
> property 'Attr' for type 'Node!string' /d228/f410.d(14): Error:
> no property 'Attr' for type 'Node!string'
>
> So question is: is this intended behaviour and I'm missing
> something about eponymous templates? Or is it a bug in compiler?
Looks like compiler looks for Node, Name and Attr in Node struct,
because of eponymous thing.
This code works though:
template N(String)
{
struct Node {}
struct Name {}
struct Attr {}
}
void main()
{
alias MyNode = N!(string).Node;
alias MyName = N!(string).Name;
alias MyAttr = N!(string).Attr;
}
More information about the Digitalmars-d-learn
mailing list