I wondered if this is a current limitation of chunkBy implementation:

// http://dpaste.dzfl.pl/52d6a0c5d0ab
void bar(int[] foo)
{
        bool less(int a, int b) // contrived
        {
                return a < b;
        };

        foo.sort!less.groupBy;
}

resulting in:

/opt/compilers/dmd2/include/std/algorithm/iteration.d(1529): Error: function f351.bar.SortedRange!(int[], less).SortedRange.groupBy!().groupBy.ChunkByImpl!(__lambda1, int[]).ChunkByImpl.Group.popFront cannot access frame of function f351.bar.SortedRange!(int[], less).SortedRange.groupBy!().groupBy
...

I can see that the implementation of chunkBy is nested:
struct ChunkByImpl
{
        static struct Group {}
}

and that the predicate (less in this case) is accessed from the nested struct Group which is, probably, what's causing the compilation error.

The question is if this is an implementation error (i.e. Group should probably be moved to the top level) or a compiler issue?

Thanks in advance.

Reply via email to