On Friday, 2 October 2015 at 18:16:59 UTC, Ali Çehreli wrote:
On 10/02/2015 02:21 AM, Dmitri wrote:
> [...]
implementation:
> [...]
Error:
> [...]
function
> [...]
less).SortedRange.groupBy!().groupBy
> [...]
the nested
> [...]
compilation error.
> [...]
Group should
> [...]
This is a known D issue. Currently, objects have a single
context pointer. Here is a bug discussion about it:
https://issues.dlang.org/show_bug.cgi?id=5710
A workaround for your example is making less() static, which
removes its context pointer:
void bar(int[] foo)
{
import std.algorithm : sort;
static bool less(int a, int b) // contrived
{
return a < b;
}
foo.sort!less.groupBy;
}
void main() {}
I've just realized that I don't know how to handle the case
where less() really needs some other state (e.g. it may need to
use a local variable in main). What can we do?
Ali
Thanks, Ali - this is helpful. The problem was figuring out what
exactly is wrong given a bunch of unhelpful error messages. A
somewhat better message comes when using a unary predicate
version of chunkBy.