digitalmars.D.learn - Template mixin identifier as template alias parameter
- Jack Applegame (29/29) Nov 11 2012 I'm trying creating template for intrusive double-linked list:
- Jacob Carlborg (5/21) Nov 11 2012 This won't work. The "node" template doesn't evaluate to a type and you
- Jack Applegame (16/18) Nov 11 2012 But this is works! Why?
- David Nadlinger (7/9) Nov 11 2012 You _can_ actually use an identifier for mixin templates, it is
I'm trying creating template for intrusive double-linked list: mixin template node() { static if(is(this == struct)) alias typeof(this)* E; else alias typeof(this) E; E prev, next; } struct list(alias N) { N.E head; N.E tail; } class A { mixin node; } list!A l; All works great. If it's need to store one object in two different lists I plan something like this: class A { mixin node L1; mixin node L2; } list!(A.L1) l1; list!(A.L2) l2; But compiler doesn't compile that whith error: "this is not in a class or struct scope|" in line with "alias typeof(this) E;"
Nov 11 2012
On 2012-11-11 10:04, Jack Applegame wrote:I'm trying creating template for intrusive double-linked list: mixin template node() { static if(is(this == struct)) alias typeof(this)* E; else alias typeof(this) E; E prev, next; } class A { mixin node L1; mixin node L2; }This won't work. The "node" template doesn't evaluate to a type and you wouldn't use it as a mixin if it did.But compiler doesn't compile that whith error: "this is not in a class or struct scope|" in line with "alias typeof(this) E;"-- /Jacob Carlborg
Nov 11 2012
On Sunday, 11 November 2012 at 10:36:42 UTC, Jacob Carlborg wrote:This won't work. The "node" template doesn't evaluate to a type and you wouldn't use it as a mixin if it did.But this is works! Why? mixin template node() { alias int E; E prev, next; } struct list(alias N) { N.E head; N.E tail; } class A { mixin node L1; mixin node L2; } list!(A.L1) l1; list!(A.L2) l2;
Nov 11 2012
On Sunday, 11 November 2012 at 10:36:42 UTC, Jacob Carlborg wrote:This won't work. The "node" template doesn't evaluate to a type and you wouldn't use it as a mixin if it did.You _can_ actually use an identifier for mixin templates, it is used to disambiguate in case of name collisions. As far as the original question goes, I don't see a reason why this shouldn't work; you might want to add a bug report at http://d.puremagic.com/issues. David
Nov 11 2012