Horizon
adjacent_remove_if.hpp
Go to the documentation of this file.
1 // Range v3 library
3 //
4 // Copyright Eric Niebler
5 // Copyright Christopher Di Bella
6 //
7 // Use, modification and distribution is subject to the
8 // Boost Software License, Version 1.0. (See accompanying
9 // file LICENSE_1_0.txt or copy at
10 // http://www.boost.org/LICENSE_1_0.txt)
11 //
12 // Project home: https://github.com/ericniebler/range-v3
13 //
14 #ifndef RANGES_V3_ALGORITHM_ADJACENT_REMOVE_IF_HPP
15 #define RANGES_V3_ALGORITHM_ADJACENT_REMOVE_IF_HPP
16 
17 #include <functional>
18 #include <utility>
19 
20 #include <range/v3/range_fwd.hpp>
21 
32 #include <range/v3/utility/static_const.hpp>
33 
34 #include <range/v3/detail/prologue.hpp>
35 
36 namespace ranges
37 {
40  RANGES_FUNC_BEGIN(adjacent_remove_if)
47  template(typename I, typename S, typename Pred, typename Proj = identity)(
48  requires permutable<I> AND sentinel_for<S, I> AND
49  indirect_relation<Pred, projected<I, Proj>>)
50  constexpr I RANGES_FUNC(adjacent_remove_if)(I first, S last, Pred pred = {}, Proj proj = {})
51  {
52  first = adjacent_find(std::move(first), last, ranges::ref(pred), ranges::ref(proj));
53  if(first == last)
54  return first;
55 
56  auto i = first;
57  for(auto j = ++i; ++j != last; ++i)
58  {
59  if(!invoke(pred, invoke(proj, *i), invoke(proj, *j)))
60  {
61  *first = iter_move(i);
62  ++first;
63  }
64  }
65 
66  *first = iter_move(i);
67  ++first;
68  return first;
69  }
70 
72  template(typename Rng, typename Pred, typename Proj = identity)(
73  requires forward_range<Rng> AND
74  indirect_relation<Pred, projected<iterator_t<Rng>, Proj>> AND
76  constexpr borrowed_iterator_t<Rng>
77  RANGES_FUNC(adjacent_remove_if)(Rng && rng, Pred pred, Proj proj = {}) //
78  {
79  return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
80  }
81  RANGES_FUNC_END(adjacent_remove_if)
82 
83  namespace cpp20
84  {
85  using ranges::adjacent_remove_if;
86  }
88 } // namespace ranges
89 
90 #include <range/v3/detail/epilogue.hpp>
91 
92 #endif // RANGES_V3_ALGORITHM_ADJACENT_REMOVE_IF_HPP
template(typename Rng, typename Pred, typename Proj=identity)(requires forward_range< Rng > AND indirect_relation< Pred
This is an overloaded member function, provided for convenience. It differs from the above function o...
CPP_concept permutable
\concept permutable
Definition: concepts.hpp:840
CPP_concept sentinel_for
\concept sentinel_for
Definition: concepts.hpp:306
CPP_concept indirect_relation
\concept indirect_relation
Definition: concepts.hpp:670
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
Definition: identity.hpp:25