Thread overview | ||||||
---|---|---|---|---|---|---|
|
November 12, 2008 Overloaded opApply for named template mixin | ||||
---|---|---|---|---|
| ||||
Right, I have this:
template foo(T)
{
int opApply(int delegate(ref T) dg)
{
// code here
}
}
class bar(T)
{
mixin foo!(T) baz;
}
void main()
{
bar b = new bar();
foreach(qux; bar.baz)
{
}
}
And it does not compile. The error I get is "expression has no value", on the line with the foreach. Do I need to do this in a different way, or is it simply not possible (at the moment)?
--
Simen
|
November 12, 2008 Re: Overloaded opApply for named template mixin | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen Kjaeraas | On Wed, 12 Nov 2008 04:57:41 +0100, "Simen Kjaeraas" <simen.kjaras@gmail.com> wrote:
>Right, I have this:
>
>template foo(T)
>{
> int opApply(int delegate(ref T) dg)
> {
> // code here
> }
>}
>
>class bar(T)
>{
> mixin foo!(T) baz;
>}
>
>void main()
>{
> bar b = new bar();
> foreach(qux; bar.baz)
> {
> }
>}
>
>And it does not compile. The error I get is "expression has no value", on the line with the foreach. Do I need to do this in a different way, or is it simply not possible (at the moment)?
According to the spec, Aggregate in foreach can be array, class, struct or tuple. I don't know why template instances or mixins with opApply were not included. Hopefully, when foreach is updated to work with ranges, everything that looks like a range will be acceptable.
|
November 12, 2008 Re: Overloaded opApply for named template mixin | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen Kjaeraas | Em Wed, 12 Nov 2008 01:57:41 -0200, Simen Kjaeraas <simen.kjaras@gmail.com> escreveu: > Right, I have this: > > template foo(T) > { > int opApply(int delegate(ref T) dg) > { > // code here > } > } > > class bar(T) > { > mixin foo!(T) baz; > } > > void main() > { > bar b = new bar(); > foreach(qux; bar.baz) > { > } > } > > And it does not compile. The error I get is "expression has no value", on the line with the foreach. Do I need to do this in a different way, or is it simply not possible (at the moment)? > Currently the right way to do this is: template foo(T) { int opApply(int delegate(ref T) dg) { // code } } class bar(T) { mixin foo!(T); } void main() { auto b = new bar!(int); foreach(qux; b) { } } -- Usando o revolucionário cliente de e-mail do Opera: http://www.opera.com/mail/ |
November 12, 2008 Re: Overloaded opApply for named template mixin | ||||
---|---|---|---|---|
| ||||
Posted in reply to Christian Hartung | On Wed, 12 Nov 2008 11:37:33 +0100, Christian Hartung <christian.s77@gmail.com> wrote: > Currently the right way to do this is: > > template foo(T) > { > int opApply(int delegate(ref T) dg) > { > // code > } > } > > class bar(T) > { > mixin foo!(T); > } > > void main() > { > auto b = new bar!(int); > foreach(qux; b) > { > } > } > Ah, but that does not give me the named mixin. Consider class Tree(T) { mixin Traverse!(Stack) depthfirst; mixin Traverse!(Queue) breadthfirst; } -- Simen |
Copyright © 1999-2021 by the D Language Foundation