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_COPY_IF_HPP
14 #define RANGES_V3_ALGORITHM_REMOVE_COPY_IF_HPP
15 
16 #include <meta/meta.hpp>
17 
18 #include <range/v3/range_fwd.hpp>
19 
20 #include <range/v3/algorithm/result_types.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/traits.hpp>
25 #include <range/v3/range/access.hpp>
26 #include <range/v3/range/concepts.hpp>
27 #include <range/v3/range/dangling.hpp>
28 #include <range/v3/range/traits.hpp>
29 #include <range/v3/utility/static_const.hpp>
30 
31 #include <range/v3/detail/prologue.hpp>
32 
33 namespace ranges
34 {
35     /// \addtogroup group-algorithms
36     /// @{
37     template<typename I, typename O>
38     using remove_copy_if_result = detail::in_out_result<I, O>;
39 
RANGES_FUNC_BEGIN(remove_copy_if)40     RANGES_FUNC_BEGIN(remove_copy_if)
41 
42         /// \brief function template \c remove_copy_if
43         template(typename I, typename S, typename O, typename C, typename P = identity)(
44             /// \pre
45             requires input_iterator<I> AND sentinel_for<S, I> AND
46             weakly_incrementable<O> AND indirect_unary_predicate<C, projected<I, P>> AND
47             indirectly_copyable<I, O>)
48         remove_copy_if_result<I, O> //
49         RANGES_FUNC(remove_copy_if)(I first, S last, O out, C pred, P proj = P{}) //
50         {
51             for(; first != last; ++first)
52             {
53                 auto && x = *first;
54                 if(!(invoke(pred, invoke(proj, x))))
55                 {
56                     *out = (decltype(x) &&)x;
57                     ++out;
58                 }
59             }
60             return {first, out};
61         }
62 
63         /// \overload
64         template(typename Rng, typename O, typename C, typename P = identity)(
65             /// \pre
66             requires input_range<Rng> AND weakly_incrementable<O> AND
67             indirect_unary_predicate<C, projected<iterator_t<Rng>, P>> AND
68             indirectly_copyable<iterator_t<Rng>, O>)
69         remove_copy_if_result<borrowed_iterator_t<Rng>, O> //
RANGES_FUNC(remove_copy_if)70         RANGES_FUNC(remove_copy_if)(Rng && rng, O out, C pred, P proj = P{}) //
71         {
72             return (*this)(
73                 begin(rng), end(rng), std::move(out), std::move(pred), std::move(proj));
74         }
75 
76     RANGES_FUNC_END(remove_copy_if)
77 
78     namespace cpp20
79     {
80         using ranges::remove_copy_if;
81         using ranges::remove_copy_if_result;
82     } // namespace cpp20
83     /// @}
84 } // namespace ranges
85 
86 #include <range/v3/detail/epilogue.hpp>
87 
88 #endif
89