Horizon
copy.hpp
Go to the documentation of this file.
1 // 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 #ifndef RANGES_V3_ALGORITHM_COPY_HPP
14 #define RANGES_V3_ALGORITHM_COPY_HPP
15 
16 #include <functional>
17 #include <utility>
18 
19 #include <range/v3/range_fwd.hpp>
20 
21 #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 copy_result = detail::in_out_result<I, O>;
39 
40  RANGES_HIDDEN_DETAIL(namespace _copy CPP_PP_LBRACE())
41  RANGES_FUNC_BEGIN(copy)
42 
44  template(typename I, typename S, typename O)(
45  requires input_iterator<I> AND sentinel_for<S, I> AND
47  constexpr copy_result<I, O> RANGES_FUNC(copy)(I first, S last, O out) //
48  {
49  for(; first != last; ++first, ++out)
50  *out = *first;
51  return {first, out};
52  }
53 
55  template(typename Rng, typename O)(
56  requires input_range<Rng> AND weakly_incrementable<O> AND
58  constexpr copy_result<borrowed_iterator_t<Rng>, O> //
59  RANGES_FUNC(copy)(Rng && rng, O out) //
60  {
61  return (*this)(begin(rng), end(rng), std::move(out));
62  }
63 
64  RANGES_FUNC_END(copy)
65  RANGES_HIDDEN_DETAIL(CPP_PP_RBRACE())
66 
67 #ifndef RANGES_DOXYGEN_INVOKED
68  struct copy_fn
69  : aux::copy_fn
70  , _copy::copy_fn
71  {
72  using aux::copy_fn::operator();
73  using _copy::copy_fn::operator();
74  };
76 #endif
77 
78  namespace cpp20
79  {
80  using ranges::copy_result;
81  using ranges::RANGES_HIDDEN_DETAIL(_copy::) copy;
82  } // namespace cpp20
83 
85 } // namespace ranges
86 
87 #include <range/v3/detail/epilogue.hpp>
88 
89 #endif
template(typename Rng, typename O)(requires input_range< Rng > AND weakly_incrementable< O > AND indirectly_copyable< iterator_t< Rng >
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 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
RANGES_INLINE_VARIABLE(detail::to_container_fn< detail::from_range< std::vector >>, to_vector) template< template< typename... > class ContT > auto to(RANGES_HIDDEN_DETAIL(detail
For initializing a container of the specified type with the elements of an Range.
Definition: conversion.hpp:399
front< Pair > first
Retrieve the first element of the pair Pair.
Definition: meta.hpp:2251
Definition: copy.hpp:32
Definition: copy.hpp:71