Overloaded opApply for named template mixin

Max Samukha samukha at voliacable.com.removethis
Wed Nov 12 02:29:16 PST 2008


On Wed, 12 Nov 2008 04:57:41 +0100, "Simen Kjaeraas"
<simen.kjaras at 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.


More information about the Digitalmars-d-learn mailing list