Horizon
copy_n.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_COPY_N_HPP
14 #define RANGES_V3_ALGORITHM_COPY_N_HPP
15 
16 #include <functional>
17 #include <tuple>
18 #include <utility>
19 
20 #include <range/v3/range_fwd.hpp>
21 
22 #include <range/v3/algorithm/result_types.hpp>
30 #include <range/v3/utility/static_const.hpp>
31 
32 #include <range/v3/detail/prologue.hpp>
33 
34 namespace ranges
35 {
38  template<typename I, typename O>
39  using copy_n_result = detail::in_out_result<I, O>;
40 
41  RANGES_FUNC_BEGIN(copy_n)
42 
43 
44  template(typename I, typename O, typename P = identity)(
45  requires input_iterator<I> AND weakly_incrementable<O> AND
46  indirectly_copyable<I, O>)
47  constexpr copy_n_result<I, O> RANGES_FUNC(copy_n)(I first, iter_difference_t<I> n, O out)
48  {
49  RANGES_EXPECT(0 <= n);
50  auto norig = n;
51  auto b = uncounted(first);
52  for(; n != 0; ++b, ++out, --n)
53  *out = *b;
54  return {recounted(first, b, norig), out};
55  }
56 
57  RANGES_FUNC_END(copy_n)
58 
59  namespace cpp20
60  {
61  using ranges::copy_n;
62  using ranges::copy_n_result;
63  } // namespace cpp20
65 } // namespace ranges
66 
67 #include <range/v3/detail/epilogue.hpp>
68 
69 #endif
template(typename I, typename O, typename P=identity)(requires input_iterator< I > AND weakly_incrementable< O > AND indirectly_copyable< I
function template copy_n
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
front< Pair > first
Retrieve the first element of the pair Pair.
Definition: meta.hpp:2251
Definition: identity.hpp:25