Попробуйте что-то вроде этого:
template<typename T>
std::vector<T> merge(std::initializer_list<std::vector<T>*> vecs)
{
size_t size = 0;
for(auto v : vecs) { size += v->size(); }
std::vector<T> ret;
ret.reserve(size);
for(auto v : vecs) { ret.insert(ret.end(), v->begin(), v->end()); }
return ret;
}
std::vector<std::string> a = {"a", "b"};
std::vector<std::string> b = {"c", "d"};
std::vector<std::string> c = {"e", "f"};
std::vector<std::string> d = {"g", "h"};
std::vector<std::string> newVector = merge({&a, &b, &c, &d});
Live Demo
В качестве альтернативы:
template<typename T>
std::vector<T> merge(std::initializer_list<std::reference_wrapper<const std::vector<T>>> vecs)
{
size_t size = 0;
for(auto &v : vecs) { size += v.get().size(); }
std::vector<T> ret;
ret.reserve(size);
for(auto &v : vecs) { ret.insert(ret.end(), v.get().begin(), v.get().end()); }
return ret;
}
std::vector<std::string> a = {"a", "b"};
std::vector<std::string> b = {"c", "d"};
std::vector<std::string> c = {"e", "f"};
std::vector<std::string> d = {"g", "h"};
std::vector<std::string> newVector = merge({std::cref(a), std::cref(b), std::cref(c), std::cref(d)});
Демо-версия