This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of Open status.

2931. Missed optimization opportunity with single-argument std::next

Section: 27.4.3 [iterator.operations] Status: Open Submitter: Morwenn Opened: 2017-02-04 Last modified: 2017-03-13

Priority: 3

View all other issues in [iterator.operations].

View all issues with Open status.


It seems that std::next is missing an optimization opportunity when taking a single parameter. The standard mandates that std::next shall call std::advance on the passed iterator and return it. For random-access iterators, it means that operator+= will be called on the iterator. However, if a single-argument overload was added to std::next, it could call ++it directly instead of std::advance(it, 1), which means that operator++ would be called instead of operator+=. This might make a small performance difference for complicated iterators such as std::deque's ones, where operator++ has a simpler logic than operator+=.

An equivalent optimization could be allowed by adding a single-argument overload to std::prev too.

[2017-03-04, Kona]

Set priority to 3. Alisdair to provide wording.

Proposed resolution: