Getting equivalent elements in a range/array

Andrej M. none at no.com
Sat May 7 21:07:19 PDT 2011


I want to turn this:
auto arr = [1, 1, 2, 3, 4, 4];

into this:
auto arr2 = [[1, 1], [2], [3], [4, 4]];

I want an array of arrays of the same elements. Lazy or not, I don't care.

I thought I could get away with this inside some while loop:
auto equals = array(filter!"a == b"(arr));
arr = arr[equals.length-1..$];

Nope.

I need this for some buffered output, where the requirement is the elements of the buffer all need to have the same properties so a function can output a buffer of elements in one call instead of calling the function for each element (the function call is expensive).


More information about the Digitalmars-d-learn mailing list