Horizon
find_if.hpp
Go to the documentation of this file.
1 // Range v3 library
3 //
4 // Copyright Eric Niebler 2013-present
5 //
6 // Use, modification and distribution is subject to the
7 // Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10 //
11 // Project home: https://github.com/ericniebler/range-v3
12 //
13 #ifndef RANGES_V3_ALGORITHM_FIND_IF_HPP
14 #define RANGES_V3_ALGORITHM_FIND_IF_HPP
15 
16 #include <utility>
17 
18 #include <range/v3/range_fwd.hpp>
19 
28 #include <range/v3/utility/static_const.hpp>
29 
30 #include <range/v3/detail/prologue.hpp>
31 
32 namespace ranges
33 {
36  RANGES_FUNC_BEGIN(find_if)
48  template(typename I, typename S, typename F, typename P = identity)(
49  requires input_iterator<I> AND sentinel_for<S, I> AND
50  indirect_unary_predicate<F, projected<I, P>>)
51  constexpr I RANGES_FUNC(find_if)(I first, S last, F pred, P proj = P{})
52  {
53  for(; first != last; ++first)
54  if(invoke(pred, invoke(proj, *first)))
55  break;
56  return first;
57  }
58 
60  template(typename Rng, typename F, typename P = identity)(
61  requires input_range<Rng> AND
62  indirect_unary_predicate<F, projected<iterator_t<Rng>, P>>)
63  constexpr borrowed_iterator_t<Rng> RANGES_FUNC(find_if)(Rng && rng, F pred, P proj = P{})
64  {
65  return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
66  }
67 
68  RANGES_FUNC_END(find_if)
69 
70  namespace cpp20
71  {
72  using ranges::find_if;
73  }
75 } // namespace ranges
76 
77 #include <range/v3/detail/epilogue.hpp>
78 
79 #endif
CPP_concept indirect_unary_predicate
\concept indirect_unary_predicate
Definition: concepts.hpp:632
typename Fn::template invoke< Args... > invoke
Evaluate the invocable Fn with the arguments Args.
Definition: meta.hpp:541
front< Pair > first
Retrieve the first element of the pair Pair.
Definition: meta.hpp:2251