File Coverage

/usr/local/lib/perl5/site_perl/5.26.1/XS/librangeV3.x/i/range/v3/view/remove_if.hpp
Criterion Covered Total %
statement 34 34 100.0
branch 15 22 68.1
condition n/a
subroutine n/a
pod n/a
total 49 56 87.5


line stmt bran cond sub pod time code
1             /// \file
2             // Range v3 library
3             //
4             // Copyright Eric Niebler 2013-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              
14             #ifndef RANGES_V3_VIEW_REMOVE_IF_HPP
15             #define RANGES_V3_VIEW_REMOVE_IF_HPP
16              
17             #include
18             #include
19             #include
20             #include
21             #include
22             #include
23             #include
24             #include
25             #include
26             #include
27             #include
28             #include
29             #include
30             #include
31              
32             RANGES_DISABLE_WARNINGS
33              
34             namespace ranges
35             {
36             inline namespace v3
37             {
38             /// \addtogroup group-views
39             /// @{
40             template
41 1914           struct RANGES_EMPTY_BASES remove_if_view
42             : view_adaptor<
43             remove_if_view,
44             Rng,
45             is_finite::value ? finite : range_cardinality::value>
46             , private box>
47             {
48             remove_if_view() = default;
49 319           constexpr remove_if_view(Rng rng, Pred pred)
50 319           : remove_if_view::view_adaptor{detail::move(rng)}
51 319           , remove_if_view::box(detail::move(pred))
52 319           {}
53             private:
54             friend range_access;
55              
56             struct adaptor : adaptor_base
57             {
58             adaptor() = default;
59 638           constexpr adaptor(remove_if_view &rng) noexcept
60 638           : rng_(&rng)
61 638           {}
62 319           static RANGES_CXX14_CONSTEXPR iterator_t begin(remove_if_view &rng)
63             {
64 319           return *rng.begin_;
65             }
66 154           RANGES_CXX14_CONSTEXPR void next(iterator_t &it) const
67             {
68 308 50         RANGES_ASSERT(it != ranges::end(rng_->base()));
69 154           rng_->satisfy_forward(++it);
70 154           }
71             CONCEPT_REQUIRES(BidirectionalRange())
72             RANGES_CXX14_CONSTEXPR void prev(iterator_t &it) const
73             {
74             rng_->satisfy_reverse(it);
75             }
76             void advance() = delete;
77             void distance_to() = delete;
78             private:
79             remove_if_view *rng_;
80             };
81 319           RANGES_CXX14_CONSTEXPR adaptor begin_adaptor()
82             {
83 319           cache_begin();
84 319           return {*this};
85             }
86             CONCEPT_REQUIRES(!BoundedRange())
87             constexpr adaptor_base end_adaptor() const noexcept
88             {
89             return {};
90             }
91             CONCEPT_REQUIRES(BoundedRange())
92 319           RANGES_CXX14_CONSTEXPR adaptor end_adaptor()
93             {
94 319 50         if(BidirectionalRange()) cache_begin();
95 319           return {*this};
96             }
97              
98 473           RANGES_CXX14_CONSTEXPR void satisfy_forward(iterator_t &it)
99             {
100 473           auto const last = ranges::end(this->base());
101 473           auto &pred = this->remove_if_view::box::get();
102 9561 100         while (it != last && invoke(pred, *it))
    50          
    100          
    100          
103             ++it;
104 473           }
105             RANGES_CXX14_CONSTEXPR void satisfy_reverse(iterator_t &it)
106             {
107             RANGES_ASSERT(begin_);
108             auto const &first = *begin_;
109             auto &pred = this->remove_if_view::box::get();
110             do
111             {
112             RANGES_ASSERT(it != first); (void)first;
113             --it;
114             } while(invoke(pred, *it));
115             }
116              
117 638           RANGES_CXX14_CONSTEXPR void cache_begin()
118             {
119 638 100         if(begin_) return;
120 319           auto it = ranges::begin(this->base());
121 319 50         satisfy_forward(it);
122 638           begin_.emplace(std::move(it));
123             }
124              
125             detail::non_propagating_cache> begin_;
126             };
127              
128             namespace view
129             {
130             /// \cond
131             template
132             struct remove_if_fn_
133             {
134             private:
135             friend view_access;
136             template
137 319           static auto bind(remove_if_fn_ remove_if, Pred pred)
138 319 50         RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
    50          
139             (
140             make_pipeable(std::bind(remove_if, std::placeholders::_1,
141             protect(std::move(pred))))
142             )
143              
144             template
145             static auto bind(remove_if_fn_ remove_if, Pred pred, Proj proj)
146             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
147             (
148             make_pipeable(std::bind(remove_if, std::placeholders::_1,
149             protect(std::move(pred)), protect(std::move(proj))))
150             )
151             public:
152             template
153             using Constraint = meta::and_<
154             InputRange,
155             IndirectPredicate, Proj>>>;
156              
157             template
158             typename M = detail::decay_t>,
159             CONCEPT_REQUIRES_(Constraint())>
160             RANGES_CXX14_CONSTEXPR
161 319           auto operator()(Rng &&rng, Pred&& pred) const
162 319 50         RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
163             (
164             remove_if_view, M>{
165             all(static_cast(rng)),
166             Modifier{}(std::move(pred))
167             }
168             )
169              
170             template
171             typename M = detail::decay_t>,
172             CONCEPT_REQUIRES_(Constraint())>
173             RANGES_CXX14_CONSTEXPR
174             auto operator()(Rng &&rng, Pred pred, Proj proj) const
175             RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
176             (
177             remove_if_view, composed>{
178             all(static_cast(rng)),
179             compose(Modifier{}(std::move(pred)), std::move(proj))
180             }
181             )
182              
183             #ifndef RANGES_DOXYGEN_INVOKED
184             template
185             CONCEPT_REQUIRES_(!Constraint())>
186             void operator()(Rng &&, Pred) const
187             {
188             CONCEPT_ASSERT_MSG(InputRange(),
189             "The first argument to view::remove_if/filter must "
190             "be a model of the InputRange concept");
191             using Itr = iterator_t;
192             CONCEPT_ASSERT_MSG(IndirectPredicate(),
193             "The second argument to view::remove_if/filter must "
194             "accept arguments of the range's value type.");
195             }
196              
197             template
198             CONCEPT_REQUIRES_(!Constraint())>
199             void operator()(Rng &&, Pred, Proj) const
200             {
201             CONCEPT_ASSERT_MSG(InputRange(),
202             "The first argument to view::remove_if/filter must "
203             "be a model of the InputRange concept");
204             using Itr = iterator_t;
205             CONCEPT_ASSERT_MSG(IndirectInvocable(),
206             "The projection function must accept arguments of the iterator's "
207             "value type, reference type, and common reference type.");
208             CONCEPT_ASSERT_MSG(IndirectPredicate>(),
209             "The second argument to view::remove_if/filter must accept values "
210             "returned by the projection function.");
211             }
212             #endif
213             };
214             /// \endcond
215              
216             /// Given a source range, unary predicate, and optional projection,
217             /// present a view of the elements that do not satisfy the predicate.
218             using remove_if_fn = remove_if_fn_;
219              
220             /// \relates remove_if_fn
221             /// \ingroup group-views
222             RANGES_INLINE_VARIABLE(view, remove_if)
223             }
224             /// @}
225             }
226             }
227              
228             RANGES_RE_ENABLE_WARNINGS
229              
230             RANGES_SATISFY_BOOST_RANGE(::ranges::v3::remove_if_view)
231              
232             #endif