Successively prepending to slices.
monarch_dodra
monarchdodra at gmail.com
Thu Apr 10 14:05:20 PDT 2014
On Thursday, 10 April 2014 at 20:03:46 UTC, JR wrote:
> In my NewlineBufferThingy struct, I sometimes need to move a
> slice at an arbitrary point of an array to the very beginning
> of it, like a poor man's circular buffer.
Just in case somebody is wondering, phobos has std.range.cycle
for circular buffers.
> I ended up using std.algorithm.copy for that, but in your case
> -- once more, depending on your use-case -- that could end up
> in a *lot* of copying.
You may want to consider looking at std.algorithm.bringToFront.
I've never used it before, but it claims:
The bringToFront function has considerable flexibility and
usefulness. It can rotate elements in one buffer left or right,
swap buffers of equal length, and even move elements across
disjoint buffers of different types and different lengths.
I don't know how efficient or certifiably correct it actually is.
More information about the Digitalmars-d-learn
mailing list