Debian Codegraph @

3rd_party/range-v3/range/v3/view/remove.hpp

raw
1 /// \file
2 // Range v3 library
3 //
4 // Copyright Andrey Diduh 2019
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
14 #ifndef RANGES_V3_VIEW_REMOVE_HPP
15 #define RANGES_V3_VIEW_REMOVE_HPP
16
17 #include <type_traits>
18 #include <utility>
19
20 #include <meta/meta.hpp>
21
22 #include <concepts/concepts.hpp>
23
24 #include <range/v3/range_fwd.hpp>
25
26 #include <range/v3/functional/bind_back.hpp>
27 #include <range/v3/functional/comparisons.hpp>
28 #include <range/v3/view/remove_if.hpp>
29 #include <range/v3/view/view.hpp>
30
31 #include <range/v3/detail/prologue.hpp>
32
33 namespace ranges
34 {
35 /// \addtogroup group-views
36 /// @{
37 namespace views
38 {
39 struct remove_base_fn
40 {
41 private:
42 template<typename Value>
43 struct pred_
44 {
45 Value value_;
46 template(typename T)(
47 requires equality_comparable_with<T, Value const &>)
48 bool operator()(T && other) const
49 {
50 return static_cast<T &&>(other) == value_;
51 }
52 };
53
54 public:
55 template(typename Rng, typename Value)(
56 requires move_constructible<Value> AND viewable_range<Rng> AND
57 input_range<Rng> AND
58 indirectly_comparable<iterator_t<Rng>, Value const *, equal_to>)
59 constexpr auto operator()(Rng && rng, Value value) const
60 {
61 return remove_if(static_cast<Rng &&>(rng),
62 pred_<Value>{std::move(value)});
63 }
64
65 template(typename Rng, typename Value, typename Proj)(
66 requires move_constructible<Value> AND viewable_range<Rng> AND
67 input_range<Rng> AND
68 indirectly_comparable<iterator_t<Rng>, Value const *, equal_to, Proj>)
69 constexpr auto operator()(Rng && rng, Value value, Proj proj) const
70 {
71 return remove_if(static_cast<Rng &&>(rng),
72 pred_<Value>{std::move(value)},
73 std::move(proj));
74 }
75 };
76
77 struct remove_bind_fn
78 {
79 template<typename Value>
80 constexpr auto operator()(Value value) const // TODO: underconstrained
81 {
82 return make_view_closure(bind_back(remove_base_fn{}, std::move(value)));
83 }
84 template(typename Value, typename Proj)(
85 requires (!range<Value>)) // TODO: underconstrained
86 constexpr auto operator()(Value && value, Proj proj) const
87 {
88 return make_view_closure(bind_back(
89 remove_base_fn{}, static_cast<Value &&>(value), std::move(proj)));
90 }
91 };
92
93 struct RANGES_EMPTY_BASES remove_fn
94 : remove_base_fn, remove_bind_fn
95 {
96 using remove_base_fn::operator();
97 using remove_bind_fn::operator();
98 };
99
100 /// \relates remove_fn
101 /// \ingroup group-views
102 RANGES_INLINE_VARIABLE(remove_fn, remove)
103 } // namespace views
104 /// @}
105 } // namespace ranges
106
107 #include <range/v3/detail/epilogue.hpp>
108
109 #endif // RANGES_V3_VIEW_REMOVE_HPP