https://issues.dlang.org/show_bug.cgi?id=13936
--- Comment #17 from Andrei Alexandrescu <and...@erdani.com> --- I recreated GroupBy as I envision it from scratch in http://dpaste.dzfl.pl/93a13ee08cc1. So: * Each group has a group counter that "stamps" it to identify it from the other groups. * Within a group iteration is fast: there's no additional indirection and one iteration evaluates one empty, one predicate, and one popBack. * At the end of each group, the next group for the mothership is primed. That way the repeated O(groupLength) iteration is saved. * Each mothership allocates memory for one payload, which will be then freed when the mothership and all of its groups go away. * Copying one mothership will work but groups originating from one given mothership only help that particular mothership. The code is only a proof of concept - it doesn't account for input vs. forward ranges, has scant testing etc. Does my vision make sense? --