相关疑难解决方法(0)

连接一系列std :: arrays

请考虑以下事项:(Wandbox)

#include <array>
#include <algorithm>
#include <iostream>

template<typename T, int N, int M>
auto concat(const std::array<T, N>& ar1, const std::array<T, M>& ar2)
{
    std::array<T, N+M> result;
    std::copy (ar1.cbegin(), ar1.cend(), result.begin());
    std::copy (ar2.cbegin(), ar2.cend(), result.begin() + N);
    return result;
}

int main()
{
    std::array<int, 3> ar1 = {1, 2, 3};
    std::array<int, 2> ar2 = {4, 5};
    auto result = concat<int, 3, 2>(ar1, ar2);
    for (auto& x : result)
        std::cout << x << " ";
    std::cout << std::endl;
    return 0; …
Run Code Online (Sandbox Code Playgroud)

c++ arrays templates c++11

10
推荐指数
3
解决办法
759
查看次数

标签 统计

arrays ×1

c++ ×1

c++11 ×1

templates ×1