Horizon
Loading...
Searching...
No Matches
copy_n.hpp
Go to the documentation of this file.
1
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_COPY_N_HPP
14#define RANGES_V3_ALGORITHM_COPY_N_HPP
15
16#include <functional>
17#include <tuple>
18#include <utility>
19
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
34namespace 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
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
The indirectly_copyable concept.
The input_iterator concept.
The weakly_incrementable concept.
Definition identity.hpp:25