This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofCD1 status.
Section: 26.7.11[alg.rotate]Status:CD1Submitter: Howard HinnantOpened: 2004-11-22Last modified: 2016-01-28
Priority:Not Prioritized
View all otherissues in [alg.rotate].
View all issues withCD1 status.
Discussion:
rotate takes 3 iterators: first, middle and last which point into asequence, and rearranges the sequence such that the subrange [middle,last) is now at the beginning of the sequence and the subrange [first,middle) follows. The return type is void.
In many use cases of rotate, the client needs to know where thesubrange [first, middle) starts after the rotate is performed. Thismight look like:
rotate(first, middle, last); Iterator i = advance(first, distance(middle, last));
Unless the iterators are random access, the computation to find thestart of the subrange [first, middle) has linear complexity. However,it is not difficult for rotate to return this information withnegligible additional computation expense. So the client could code:
Iterator i = rotate(first, middle, last);
and the resulting program becomes significantly more efficient.
While the backwards compatibility hit with this change is not zero, itis very small (similar to that of lwg130(i)), and there isa significant benefit to the change.
Proposed resolution:
In 26[algorithms] p2, change:
template<class ForwardIterator>voidForwardIterator rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);
In 26.7.11[alg.rotate], change:
template<class ForwardIterator>voidForwardIterator rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);
In 26.7.11[alg.rotate] insert a new paragraph after p1:
Returns:
first + (last - middle).
[The LWG agrees with this idea, but has one quibble: we want to makesure not to give the impression that the function "advance" isactually called, just that the nth iterator is returned. (Callingadvance is observable behavior, since users can specialize it fortheir own iterators.) Howard will provide wording.]
[Howard provided wording for mid-meeting-mailing Jun. 2005.]
[Toronto: moved to Ready.]