I’ve seen some special cases where std::rotate could be used or a combination with one of the search algorithms but generally: when one has a vector of N items and wants to code function like:
void move( int from, int count, int to, std::vector<int>& numbers );
I’ve been thinking about creation of a new vector + std::copy or combination of insert/erase but I can’t say I ended up with some nice and elegant solution.
It’s always important to profile before jumping to any conclusions. The contiguity of
vector‘s data memory may offer significant caching benefits that node-based containers don’t. So, perhaps you could give the direct approach a try:In C++11, you’d wrap the iterators in the first and third line into
std::make_move_iterator.(The requirement is that
dstnot lie within[start, start + length), or otherwise the problem is not well-defined.)