Maybe you did not want to create an std::array but a std::vector you simply can do the following. Maybe I misunderstood your question, but I hope this helps!
#include <iostream>
#include <vector>
using namespace std;
template<typename T>
vector<T> test(T begin, T end)
{
size_t size=0;
for(auto it = begin; (it != end); it++)
{
size+=it->size();
}
vector<T> ret = vector<T>(size);
return ret;
}
int main()
{
std::vector<std::vector<double>> d = { {1, 1, 1}, {2, 2, 2} };
auto ret=test(d.begin(), d.end());
cout << "Size of returned vector is " << ret.size() << endl;
return 0;
}
And if you do not want to pass iterators, you can make it a bit smaller with:
#include <iostream>
#include <vector>
using namespace std;
template<typename T>
vector<T> test(const T& matrix)
{
size_t size=0;
for( auto it: matrix)
{
size+=it.size();
}
vector<T> ret = vector<T>(size);
return ret;
}
int main()
{
std::vector<std::vector<double>> d = { {1, 1, 1}, {2, 2, 2} };
auto ret=test(d);
cout << "Size of returned vector is " << ret.size() << endl;
return 0;
}