This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of NAD status.
rotate()'s return value is incorrect when middle == firstSection: 26.7.11 [alg.rotate] Status: NAD Submitter: Stephan T. Lavavej Opened: 2014-06-14 Last modified: 2014-06-17
Priority: Not Prioritized
View all other issues in [alg.rotate].
View all issues with NAD status.
Discussion:
When LWG 488(i) was resolved, the intention was to return "where the subrange [first, middle) starts after
the rotate is performed". However, this wasn't achieved in one case.
middle == last, rotate() does nothing and returns first. This is good.
When middle == first, rotate() does nothing and returns last. This is bad. In addition to being
inconsistent with the other do-nothing case, it prevents rotate() from providing the useful guarantee that LWG
488(i) wanted: when [first, last) is non-empty, rotate()'s return value should always be
dereferenceable to get the originally-first element.
Howard Hinnant:
As the author of LWG 488(i) I can assure everyone that the edge cases the proposed resolution specifies were
not specified by accident. rotate(i, i, j) should return j and rotate(i, j, j) should return i.
Doing otherwise will break working code. These return values were motivated by the uses of rotate in the implementation
of algorithms such as stable_partition and inplace_merge. The results of these edge cases were not chosen lightly.
Also a good read:
notes-on-programming-2006-10-13
Summary: NAD.
[2014-06-16 Rapperswill]
Closed as NAD.
Proposed resolution:
This wording is relative to N3936.
Change 26.7.11 [alg.rotate] p2 as indicated:
-2- Returns:
first + (last - middle).