Title
search_n complexity is too lax
Status
cd1
Section
[alg.search]
Submitter
Matt Austern

Created on 2007-08-30.00:00:00 last changed 172 months ago

Messages

Date: 2010-10-21.18:28:33

Proposed resolution:

Change the complexity to "At most (last - first) applications of the corresponding predicate".

template<class ForwardIterator, class Size, class T> 
  ForwardIterator 
    search_n(ForwardIterator first , ForwardIterator last , Size count , 
             const T& value ); 

template<class ForwardIterator, class Size, class T, 
         class BinaryPredicate> 
  ForwardIterator 
    search_n(ForwardIterator first , ForwardIterator last , Size count , 
             const T& value , BinaryPredicate pred );

Complexity: At most (last - first ) * count applications of the corresponding predicate if count is positive, or 0 otherwise.

Date: 2007-08-30.00:00:00

The complexity for search_n ([alg.search] par 7) is specified as "At most (last - first ) * count applications of the corresponding predicate if count is positive, or 0 otherwise." This is unnecessarily pessimistic. Regardless of the value of count, there is no reason to examine any element in the range more than once.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg3519
2007-08-30 00:00:00admincreate