tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
copy_n.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4#ifndef TETL_ALGORITHM_COPY_N_HPP
5#define TETL_ALGORITHM_COPY_N_HPP
6
7namespace etl {
8
9/// Copies exactly count values from the range beginning at first to the
10/// range beginning at result. Formally, for each integer `0 <= i < count`,
11/// performs `*(result + i) = *(first + i)`. Overlap of ranges is formally
12/// permitted, but leads to unpredictable ordering of the results.
13///
14/// \returns Iterator in the destination range, pointing past the last element
15/// copied if count>0 or result otherwise.
16/// \ingroup algorithm
17template <typename InputIt, typename Size, typename OutputIt>
18constexpr auto copy_n(InputIt first, Size count, OutputIt result) -> OutputIt
19{
20 if (count > 0) {
21 *result = *first;
22 for (Size i = 1; i < count; ++i) {
23 *(++result) = *(++first);
24 }
25 }
26 return result;
27}
28
29} // namespace etl
30
31#endif // TETL_ALGORITHM_COPY_N_HPP
constexpr auto copy_n(InputIt first, Size count, OutputIt result) -> OutputIt
Copies exactly count values from the range beginning at first to the range beginning at result....
Definition copy_n.hpp:18
Definition adjacent_find.hpp:9