Horizon
adjacent_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_ADJACENT_FIND_HPP
14 #define RANGES_V3_ALGORITHM_ADJACENT_FIND_HPP
15 
16 #include <range/v3/range_fwd.hpp>
17 
26 #include <range/v3/utility/static_const.hpp>
27 
28 #include <range/v3/detail/prologue.hpp>
29 
30 namespace ranges
31 {
34  RANGES_FUNC_BEGIN(adjacent_find)
41  template(typename I, typename S, typename C = equal_to, typename P = identity)(
42  requires forward_iterator<I> AND sentinel_for<S, I> AND
43  indirect_relation<C, projected<I, P>>)
44  constexpr I RANGES_FUNC(adjacent_find)(I first, S last, C pred = C{}, P proj = P{})
45  {
46  if(first == last)
47  return first;
48  auto inext = first;
49  for(; ++inext != last; first = inext)
50  if(invoke(pred, invoke(proj, *first), invoke(proj, *inext)))
51  return first;
52  return inext;
53  }
54 
56  template(typename Rng, typename C = equal_to, typename P = identity)(
57  requires forward_range<Rng> AND
58  indirect_relation<C, projected<iterator_t<Rng>, P>>)
59  constexpr borrowed_iterator_t<Rng> //
60  RANGES_FUNC(adjacent_find)(Rng && rng, C pred = C{}, P proj = P{}) //
61  {
62  return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
63  }
64  RANGES_FUNC_END(adjacent_find)
65 
66  namespace cpp20
67  {
68  using ranges::adjacent_find;
69  }
71 } // namespace ranges
72 
73 #include <range/v3/detail/epilogue.hpp>
74 
75 #endif // RANGE_ALGORITHM_ADJACENT_FIND_HPP
template(typename Rng, typename C=equal_to, typename P=identity)(requires forward_range< Rng > AND indirect_relation< C
This is an overloaded member function, provided for convenience. It differs from the above function o...
CPP_concept sentinel_for
\concept sentinel_for
Definition: concepts.hpp:306
CPP_concept indirect_relation
\concept indirect_relation
Definition: concepts.hpp:670
CPP_concept forward_iterator
\concept forward_iterator
Definition: concepts.hpp:370
decltype(begin(declval(Rng &))) iterator_t
Definition: access.hpp:698
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
Definition: comparisons.hpp:28
Definition: identity.hpp:25