Horizon
find.hpp
Go to the documentation of this file.
1 // Range v3 library
3 //
4 // Copyright Eric Niebler 2014-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_HPP
14 #define RANGES_V3_ALGORITHM_FIND_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)
46  template(typename I, typename S, typename V, typename P = identity)(
47  requires input_iterator<I> AND sentinel_for<S, I> AND
48  indirect_relation<equal_to, projected<I, P>, V const *>)
49  constexpr I RANGES_FUNC(find)(I first, S last, V const & val, P proj = P{})
50  {
51  for(; first != last; ++first)
52  if(invoke(proj, *first) == val)
53  break;
54  return first;
55  }
56 
58  template(typename Rng, typename V, typename P = identity)(
59  requires input_range<Rng> AND
60  indirect_relation<equal_to, projected<iterator_t<Rng>, P>, V const *>)
61  constexpr borrowed_iterator_t<Rng> //
62  RANGES_FUNC(find)(Rng && rng, V const & val, P proj = P{})
63  {
64  return (*this)(begin(rng), end(rng), val, std::move(proj));
65  }
66 
67  RANGES_FUNC_END(find)
68 
69  namespace cpp20
70  {
71  using ranges::find;
72  }
74 } // namespace ranges
75 
76 #include <range/v3/detail/epilogue.hpp>
77 
78 #endif
CPP_concept indirect_relation
\concept indirect_relation
Definition: concepts.hpp:670
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
bool_< T::type::value==U::type::value > equal_to
A Boolean integral constant wrapper around the result of comparing T::type::value and U::type::value ...
Definition: meta.hpp:237