Horizon
remove.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_REMOVE_HPP
14 #define RANGES_V3_ALGORITHM_REMOVE_HPP
15 
16 #include <meta/meta.hpp>
17 
18 #include <range/v3/range_fwd.hpp>
19 
30 #include <range/v3/utility/static_const.hpp>
31 
32 #include <range/v3/detail/prologue.hpp>
33 
34 namespace ranges
35 {
38  RANGES_FUNC_BEGIN(remove)
39 
40 
41  template(typename I, typename S, typename T, typename P = identity)(
42  requires permutable<I> AND sentinel_for<S, I> AND
43  indirect_relation<equal_to, projected<I, P>, T const *>)
44  constexpr I RANGES_FUNC(remove)(I first, S last, T const & val, P proj = P{})
45  {
46  first = find(std::move(first), last, val, ranges::ref(proj));
47  if(first != last)
48  {
49  for(I i = next(first); i != last; ++i)
50  {
51  if(!(invoke(proj, *i) == val))
52  {
53  *first = iter_move(i);
54  ++first;
55  }
56  }
57  }
58  return first;
59  }
60 
62  template(typename Rng, typename T, typename P = identity)(
63  requires forward_range<Rng> AND permutable<iterator_t<Rng>> AND
64  indirect_relation<equal_to, projected<iterator_t<Rng>, P>, T const *>)
65  constexpr borrowed_iterator_t<Rng> //
66  RANGES_FUNC(remove)(Rng && rng, T const & val, P proj = P{})
67  {
68  return (*this)(begin(rng), end(rng), val, std::move(proj));
69  }
70 
71  RANGES_FUNC_END(remove)
72 
73  namespace cpp20
74  {
75  using ranges::remove;
76  }
78 } // namespace ranges
79 
80 #include <range/v3/detail/epilogue.hpp>
81 
82 #endif
CPP_concept permutable
\concept permutable
Definition: concepts.hpp:840
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
drop< L, min< find_index< L, T >, size< L > >> find
Return the tail of the list L starting at the first occurrence of T, if any such element exists; the ...
Definition: meta.hpp:2388
Tiny meta-programming library.