Files
cppdraft_translate/cppdraft/alg/find.md
2025-10-25 03:02:53 +03:00

9.9 KiB
Raw Blame History

[alg.find]

26 Algorithms library [algorithms]

26.6 Non-modifying sequence operations [alg.nonmodifying]

26.6.6 Find [alg.find]

🔗

`template<class InputIterator, class T = iterator_traits::value_type> constexpr InputIterator find(InputIterator first, InputIterator last, const T& value); template<class ExecutionPolicy, class ForwardIterator, class T = iterator_traits::value_type> 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);

template<input_iterator I, sentinel_for S, class Proj = identity, class T = projected_value_t<I, Proj>> requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*> constexpr I ranges::find(I first, S last, const T& value, Proj proj = {}); template<input_range R, class Proj = identity, class T = projected_value_t<iterator_t, Proj>> requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t, Proj>, const T*> constexpr borrowed_iterator_t ranges::find(R&& r, const T& value, Proj proj = {});

template<execution-policy Ep, random_access_iterator I, sized_sentinel_for S, class Proj = identity, class T = projected_value_t<I, Proj>> requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*> I ranges::find(Ep&& exec, I first, S last, const T& value, Proj proj = {}); template<execution-policy Ep, sized-random-access-range R, class Proj = identity, class T = projected_value_t<iterator_t, Proj>> requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t, Proj>, const T*> borrowed_iterator_t ranges::find(Ep&& exec, R&& r, const T& value, Proj proj = {});

template<input_iterator I, sentinel_for S, class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred> constexpr I ranges::find_if(I first, S last, Pred pred, Proj proj = {}); template<input_range R, class Proj = identity, indirect_unary_predicate<projected<iterator_t, Proj>> Pred> constexpr borrowed_iterator_t ranges::find_if(R&& r, Pred pred, Proj proj = {});

template<execution-policy Ep, random_access_iterator I, sized_sentinel_for S, class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred> I ranges::find_if(Ep&& exec, I first, S last, Pred pred, Proj proj = {}); template<execution-policy Ep, sized-random-access-range R, class Proj = identity, indirect_unary_predicate<projected<iterator_t, Proj>> Pred> borrowed_iterator_t ranges::find_if(Ep&& exec, R&& r, Pred pred, Proj proj = {});

template<input_iterator I, sentinel_for S, class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred> constexpr I ranges::find_if_not(I first, S last, Pred pred, Proj proj = {}); template<input_range R, class Proj = identity, indirect_unary_predicate<projected<iterator_t, Proj>> Pred> constexpr borrowed_iterator_t ranges::find_if_not(R&& r, Pred pred, Proj proj = {});

template<execution-policy Ep, random_access_iterator I, sized_sentinel_for S, class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred> I ranges::find_if_not(Ep&& exec, I first, S last, Pred pred, Proj proj = {}); template<execution-policy Ep, sized-random-access-range R, class Proj = identity, indirect_unary_predicate<projected<iterator_t, Proj>> Pred> borrowed_iterator_t ranges::find_if_not(Ep&& exec, R&& r, Pred pred, Proj proj = {}); `

1

#

Let E be:

*i == value for find;

pred(*i) != false for find_if;

pred(*i) == false for find_if_not;

bool(invoke(proj, *i) == value) for ranges::find;

bool(invoke(pred, invoke(proj, *i))) for ranges::find_if;

bool(!invoke(pred, invoke(proj, *i))) for ranges::find_if_not.

2

#

Returns: The first iterator i in the range [first, last) for which E is true.

Returns last if no such iterator is found.

3

#

Complexity: At most last - first applications of the corresponding predicate and any projection.