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.

### 2405. `rotate()`'s return value is incorrect when `middle == first`

Section: 25.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 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.

When `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 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 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.

1. Change 25.7.11 [alg.rotate] p2 as indicated:

   > -2- Returns: If `middle == first`, returns `first`. Otherwise, returns `first + (last - middle)`.