Title
Missed optimization opportunity with single-argument std::next
Status
open
Section
[iterator.operations]
Submitter
Morwenn

Created on 2017-02-04.00:00:00 last changed 73 months ago

Messages

Date: 2018-11-15.00:00:00

[ 2018-11-30, Jonathan comments, recommending NAD ]

Jonathan suggested NAD, because the proposed "just use increment when n==1" optimization can be done in std::next (and/or std::advance, and/or complicated iterators like deque::iterator) without adding an overload. Billy said the overload would avoid metaprogramming costs for dispatching to the right std::advance, and help in non-optimized builds. Zhihao said the overload would make it clear to users that the n==1 case is optimized (Jonathan thinks this is irrelevant as there's no requirement that we tell users what we optimize).

Date: 2017-03-15.00:00:00

[ 2017-03-04, Kona ]

Set priority to 3. Alisdair to provide wording.

Date: 2017-02-04.00:00:00

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.

History
Date User Action Args
2018-12-01 15:27:06adminsetmessages: + msg10241
2017-03-14 03:14:09adminsetmessages: + msg9115
2017-03-14 03:14:09adminsetstatus: new -> open
2017-02-04 00:00:00admincreate