This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofC++11 status.
Section: 26.6.15[alg.search]Status:C++11Submitter: Howard HinnantOpened: 2010-06-25Last modified: 2016-01-28
Priority:Not Prioritized
View all otherissues in [alg.search].
View all issues withC++11 status.
Discussion:
LWG1205(i) (currently in WP) clarified the return value of severalalgorithms when dealing with empty ranges. In particular it recommended for26.6.15[alg.search]:
template<class ForwardIterator1, class ForwardIterator2> ForwardIterator1 search(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2);template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> ForwardIterator1 search(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);1Effects: ...
2Returns: ... Returns
last1if no such iterator is found.3Remarks: Returns
first1if[first2,last2)is empty.
Unfortunately this got translated to an incorrect specification for what getsreturned when no such iterator is found (N3092):
template<class ForwardIterator1, class ForwardIterator2> ForwardIterator1 search(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2);template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> ForwardIterator1 search(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);1Effects: ...
2Returns: ... Returns
first1if[first2,last2)isempty or if no such iterator is found.
LWG1205(i) is correct and N3092 is not equivalent nor correct.
I have not reviewed the other 10 recommendations of1205(i).
[Post-Rapperswil]
It was verified that none of the remaining possibly affected algorithms does have any similar problems and a concrete P/R was added that used a similar style as has been applied to the other cases.
Moved to Tentatively Ready after 5 positive votes on c++std-lib.
[Adopted at 2010-11 Batavia]
Proposed resolution:
template<class ForwardIterator1, class ForwardIterator2> ForwardIterator1 search(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2);template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> ForwardIterator1 search(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);1 - [...]
2 -Returns: The first iteratoriin the range[first1,last1 - (last2-first2))such that for any nonnegativeintegernless thanlast2 - first2the following corresponding conditions hold:*(i + n) == *(first2 + n),pred(*(i + n), *(first2 + n)) != false. Returnsfirst1if[first2,last2)is emptyor, otherwisereturnslast1if no such iterator is found.