Debian Codegraph @

3rd_party/range-v3/range/v3/algorithm/remove_if.hpp

raw
1 /// \file
2 // 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_IF_HPP
14 #define RANGES_V3_ALGORITHM_REMOVE_IF_HPP
15
16 #include <meta/meta.hpp>
17
18 #include <range/v3/range_fwd.hpp>
19
20 #include <range/v3/algorithm/find_if.hpp>
21 #include <range/v3/functional/identity.hpp>
22 #include <range/v3/functional/invoke.hpp>
23 #include <range/v3/iterator/concepts.hpp>
24 #include <range/v3/iterator/operations.hpp>
25 #include <range/v3/iterator/traits.hpp>
26 #include <range/v3/range/access.hpp>
27 #include <range/v3/range/concepts.hpp>
28 #include <range/v3/range/dangling.hpp>
29 #include <range/v3/range/traits.hpp>
30 #include <range/v3/utility/static_const.hpp>
31
32 #include <range/v3/detail/prologue.hpp>
33
34 namespace ranges
35 {
36 /// \addtogroup group-algorithms
37 /// @{
38 RANGES_FUNC_BEGIN(remove_if)
39
40 /// \brief function template \c remove_if
41 template(typename I, typename S, typename C, typename P = identity)(
42 requires permutable<I> AND sentinel_for<S, I> AND
43 indirect_unary_predicate<C, projected<I, P>>)
44 constexpr I RANGES_FUNC(remove_if)(I first, S last, C pred, P proj = P{})
45 {
46 first = find_if(std::move(first), last, ranges::ref(pred), ranges::ref(proj));
47 if(first != last)
48 {
49 for(I i = next(first); i != last; ++i)
50 {
51 if(!(invoke(pred, invoke(proj, *i))))
52 {
53 *first = iter_move(i);
54 ++first;
55 }
56 }
57 }
58 return first;
59 }
60
61 /// \overload
62 template(typename Rng, typename C, typename P = identity)(
63 requires forward_range<Rng> AND permutable<iterator_t<Rng>> AND
64 indirect_unary_predicate<C, projected<iterator_t<Rng>, P>>)
65 constexpr borrowed_iterator_t<Rng> RANGES_FUNC(remove_if)(Rng && rng, C pred, P proj = P{})
66 {
67 return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
68 }
69
70 RANGES_FUNC_END(remove_if)
71
72 namespace cpp20
73 {
74 using ranges::remove_if;
75 }
76 /// @}
77 } // namespace ranges
78
79 #include <range/v3/detail/epilogue.hpp>
80
81 #endif