C++'s std::rotate

Dragos Carp via Digitalmars-d digitalmars-d at puremagic.com
Sun Aug 10 23:56:50 PDT 2014


Nice work!

> Implementation is at http://dpaste.dzfl.pl/a0effbaee0a9. For 
> historical reasons I've reused an undocumented function 
> sameHead.

sameHead is documented. I already use it a couple of times.

> The algorithm assumes that "right" is a subrange of "whole" 
> sitting at its tail, ...

sameTail is also in the Phobos docs. overlap is not documented.

A couple of times writing contracts, I missed something like:

bool sliceOf(T)(in T[] whole, in T[] slice)
{
     return whole.ptr <= slice.ptr &&
         whole.ptr + slice.length <= whole.ptr + slice.length;
}

The alternative using overlap:

   overlap(whole, slice) is slice

is a little bit too expensive for my use case.


More information about the Digitalmars-d mailing list