std::copy_n
                Актуально для C++23.
                #include <algorithm>
                Актуально на 2024-03-07.
                Define overload #1
template<class InputIter, class Size, class OutputIter> constexpr OutputIter copy_n(InputIter first, Size count, OutputIter out);
Копирует "count" элементов из последовательности "first" в "out".
В большинстве реализаций, если first является std::move_iterator, элементы будут перемещены, а не скопированы.
Вернёт OutputIter итератор за последним скопированным элементом или out.
Example, possible implementation
Define overload #2
template<class ExecutionPolicy, class ForwardIter1, class Size, class ForwardIter2>
ForwardIter2 copy_n(ExecutionPolicy&& policy, ForwardIter1 first,
                    Size count, ForwardIter2 out);
TODO
Example, possible implementation
Examples
Example 1:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
int main()
{
    auto data = {0, 1, 3, 5, 7};
    std::vector<int> v(4);
    std::copy_n(std::begin(data), 4, v.begin());
    for (auto x : v)
    {
        std::cout << x << std::endl;
    }
    return 0;
}
0 1 3 5
Changelog
See also
TODO
 This page was last modified on 2024-03-07