| Thread overview | ||||||
|---|---|---|---|---|---|---|
|
November 11, 2012 Template mixin identifier as template alias parameter | ||||
|---|---|---|---|---|
| ||||
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;"
| ||||
November 11, 2012 Re: Template mixin identifier as template alias parameter | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jack Applegame | 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 | |||
November 11, 2012 Re: Template mixin identifier as template alias parameter | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | 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;
| |||
November 11, 2012 Re: Template mixin identifier as template alias parameter | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | 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 | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply