Title
rotate()'s return value is incorrect when middle == first
Status
nad
Section
[alg.rotate]
Submitter
Stephan T. Lavavej

Created on 2014-06-14.00:00:00 last changed 128 months ago

Messages

Date: 2014-06-17.08:47:43

Proposed resolution:

This wording is relative to N3936.

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

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

Date: 2014-06-16.00:00:00

[ 2014-06-16 Rapperswill ]

Closed as NAD.

Date: 2014-06-14.00:00:00

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.

History
Date User Action Args
2014-06-17 08:47:43adminsetmessages: + msg7061
2014-06-17 08:47:43adminsetstatus: new -> nad
2014-06-14 19:39:50adminsetmessages: + msg7041
2014-06-14 00:00:00admincreate