24 Algorithms library [algorithms]

24.5 Non-modifying sequence operations [alg.nonmodifying]

24.5.5 Find [alg.find]

template<class InputIterator, class T> constexpr InputIterator find(InputIterator first, InputIterator last, const T& value); template<class ExecutionPolicy, class ForwardIterator, class T> ForwardIterator find(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, const T& value); template<class InputIterator, class Predicate> constexpr InputIterator find_if(InputIterator first, InputIterator last, Predicate pred); template<class ExecutionPolicy, class ForwardIterator, class Predicate> ForwardIterator find_if(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Predicate pred); template<class InputIterator, class Predicate> constexpr InputIterator find_if_not(InputIterator first, InputIterator last, Predicate pred); template<class ExecutionPolicy, class ForwardIterator, class Predicate> ForwardIterator find_if_not(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Predicate pred); namespace ranges { template<InputIterator I, Sentinel<I> S, class T, class Proj = identity> requires IndirectRelation<ranges::equal_to<>, projected<I, Proj>, const T*> constexpr I find(I first, S last, const T& value, Proj proj = {}); template<InputRange R, class T, class Proj = identity> requires IndirectRelation<ranges::equal_to<>, projected<iterator_t<R>, Proj>, const T*> constexpr safe_iterator_t<R> find(R&& r, const T& value, Proj proj = {}); template<InputIterator I, Sentinel<I> S, class Proj = identity, IndirectUnaryPredicate<projected<I, Proj>> Pred> constexpr I find_if(I first, S last, Pred pred, Proj proj = {}); template<InputRange R, class Proj = identity, IndirectUnaryPredicate<projected<iterator_t<R>, Proj>> Pred> constexpr safe_iterator_t<R> find_if(R&& r, Pred pred, Proj proj = {}); template<InputIterator I, Sentinel<I> S, class Proj = identity, IndirectUnaryPredicate<projected<I, Proj>> Pred> constexpr I find_if_not(I first, S last, Pred pred, Proj proj = {}); template<InputRange R, class Proj = identity, IndirectUnaryPredicate<projected<iterator_t<R>, Proj>> Pred> constexpr safe_iterator_t<R> find_if_not(R&& r, Pred pred, Proj proj = {}); }
Let E be:
  • *i == value for find,
  • pred(*i) != false for find_­if,
  • pred(*i) == false for find_­if_­not,
  • invoke(proj, *i) == value for ranges::find,
  • invoke(pred, invoke(proj, *i)) != false for ranges::find_­if,
  • invoke(pred, invoke(proj, *i)) == false for ranges::find_­if_­not.
Returns: The first iterator i in the range [first, last) for which E is true.
Returns last if no such iterator is found.
Complexity: At most last - first applications of the corresponding predicate and any projection.