Horizon
remove_copy.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_COPY_HPP
14 #define RANGES_V3_ALGORITHM_REMOVE_COPY_HPP
15 
16 #include <meta/meta.hpp>
17 
18 #include <range/v3/range_fwd.hpp>
19 
20 #include <range/v3/algorithm/result_types.hpp>
29 #include <range/v3/utility/static_const.hpp>
30 
31 #include <range/v3/detail/prologue.hpp>
32 
33 namespace ranges
34 {
37  template<typename I, typename O>
38  using remove_copy_result = detail::in_out_result<I, O>;
39 
40  RANGES_FUNC_BEGIN(remove_copy)
41 
42 
43  template(typename I, typename S, typename O, typename T, typename P = identity)(
44  requires input_iterator<I> AND sentinel_for<S, I> AND
46  indirect_relation<equal_to, projected<I, P>, T const *> AND
47  indirectly_copyable<I, O>)
48  constexpr remove_copy_result<I, O> RANGES_FUNC(remove_copy)(
49  I first, S last, O out, T const & val, P proj = P{}) //
50  {
51  for(; first != last; ++first)
52  {
53  auto && x = *first;
54  if(!(invoke(proj, x) == val))
55  {
56  *out = (decltype(x) &&)x;
57  ++out;
58  }
59  }
60  return {first, out};
61  }
62 
64  template(typename Rng, typename O, typename T, typename P = identity)(
65  requires input_range<Rng> AND weakly_incrementable<O> AND
66  indirect_relation<equal_to, projected<iterator_t<Rng>, P>, T const *> AND
68  constexpr remove_copy_result<borrowed_iterator_t<Rng>, O> //
69  RANGES_FUNC(remove_copy)(Rng && rng, O out, T const & val, P proj = P{}) //
70  {
71  return (*this)(begin(rng), end(rng), std::move(out), val, std::move(proj));
72  }
73 
74  RANGES_FUNC_END(remove_copy)
75 
76  namespace cpp20
77  {
78  using ranges::remove_copy;
79  using ranges::remove_copy_result;
80  } // namespace cpp20
82 } // namespace ranges
83 
84 #include <range/v3/detail/epilogue.hpp>
85 
86 #endif
template(typename Rng, typename O, typename T, typename P=identity)(requires input_range< Rng > AND weakly_incrementable< O > AND indirect_relation< equal_to
This is an overloaded member function, provided for convenience. It differs from the above function o...
CPP_concept sentinel_for
\concept sentinel_for
Definition: concepts.hpp:306
CPP_concept input_iterator
\concept input_iterator
Definition: concepts.hpp:362
CPP_concept indirect_relation
\concept indirect_relation
Definition: concepts.hpp:670
CPP_concept indirectly_copyable
\concept indirectly_copyable
Definition: concepts.hpp:782
CPP_concept weakly_incrementable
\concept weakly_incrementable
Definition: concepts.hpp:268
decltype(begin(declval(Rng &))) iterator_t
Definition: access.hpp:698
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
Tiny meta-programming library.
Definition: comparisons.hpp:28
Definition: identity.hpp:25