Why doesn't std :: advance return a resultant iterator?

Currently std::advancecreated as follows:

template< class InputIt, class Distance >
void advance( InputIt& it, Distance n );

However, I often find that I want something like:

template< class InputIt, class Distance >
InputIt advance( InputIt it, Distance n );

So what is the rationale for the current design? Is this for some performance consideration? Note that std::nextand std::prevreturns the iterator.

+4
source share
2 answers

There are no technical reasons preventing the return of a reference to an input value, and any reasonable compiler should be able to optimize the return value if it is not used. That way, they could do it that way if they wanted to.

, API, - std::prev std::next , , , .

std::advance, , . , , . .

, std::advance InputIterator s, , (, , ), std::prev std::next ForwardIterator s, .

, (, std::prev std::next) - , .

+1

, , , InputIterator , - :

InputIterators : InputIterator .

, std::advance , , . , , .

std::prev std::next , BidirectionalIterator, , , ForwardIterator:

InputIterator OutputIterator, .

, , .

- , .


, , , InputIterator, , . dyp : http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#2353.

, , .

, .

0

All Articles