Debian Codegraph @

3rd_party/range-v3/range/v3/algorithm/copy_n.hpp

raw
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_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>
23 #include <range/v3/functional/identity.hpp>
24 #include <range/v3/iterator/concepts.hpp>
25 #include <range/v3/iterator/operations.hpp>
26 #include <range/v3/iterator/traits.hpp>
27 #include <range/v3/range/access.hpp>
28 #include <range/v3/range/concepts.hpp>
29 #include <range/v3/range/traits.hpp>
30 #include <range/v3/utility/static_const.hpp>
31
32 #include <range/v3/detail/prologue.hpp>
33
34 namespace ranges
35 {
36 /// \addtogroup group-algorithms
37 /// @{
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 /// \brief function template \c copy_n
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
64 /// @}
65 } // namespace ranges
66
67 #include <range/v3/detail/epilogue.hpp>
68
69 #endif