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

219. find algorithm missing version that takes a binary predicate argument

Section: 27.6.6 [alg.find] Status: NAD Submitter: Pablo Halpern Opened: 2000-03-06 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [alg.find].

View all issues with NAD status.

Discussion:

The find function always searches for a value using operator== to compare the value argument to each element in the input iterator range. This is inconsistent with other find-related functions such as find_end and find_first_of, which allow the caller to specify a binary predicate object to be used for determining equality. The fact that this can be accomplished using a combination of find_if and bind_1st or bind_2nd does not negate the desirability of a consistent, simple, alternative interface to find.

[ Summit: ]

Reopened by Alisdair.

[ 2009-07 Frankfurt ]

The same thing can be achieved using find_if (as noted in the issue).

Moved to NAD.

Proposed resolution:

In section 27.6.6 [alg.find], add a second prototype for find (between the existing prototype and the prototype for find_if), as follows:

    template<class InputIterator, class T, class BinaryPredicate>
      InputIterator find(InputIterator first, InputIterator last,
                         const T& value, BinaryPredicate bin_pred);

Change the description of the return from:

Returns: The first iterator i in the range [first, last) for which the following corresponding conditions hold: *i == value, pred(*i) != false. Returns last if no such iterator is found.

 to:

Returns: The first iterator i in the range [first, last) for which the following  corresponding condition holds: *i == value, bin_pred(*i,value) != false, pred(*) != false. Return last if no such iterator is found.

Rationale:

This is request for a pure extension, so it is not a defect in the current standard.  As the submitter pointed out, "this can be accomplished using a combination of find_if and bind_1st or bind_2nd".