#include <iostream>
#include <initializer_list>
#include <list>
#include <vector>
#include <algorithm>
#include <iterator>
// Base case: do nothing once all inputs have been processed
void implementation(const std::list<int>& acc) {}
// Recursively pick off one sequence at a time, copying the data into
// the accumulator
template<class ONE, class ... REST>
void implementation(std::list<int>& accumulator,
const ONE& first,
const REST& ... rest) {
std::copy(begin(first), end(first), std::back_inserter(accumulator));
implementation(accumulator, rest...);
}
// Interface, hiding the creation of the accumulator being fed to the
// template-recursive implementation.
template<class ... REST>
std::vector<int> concatenate(const std::initializer_list<REST>& ... rest) {
std::list<int> accumulator;
implementation(accumulator, rest...);
return std::vector<int>(begin(accumulator), end(accumulator));
}
template<class SEQ>
void show_contents(const SEQ& s) {
std::copy(begin(s), end(s), std::ostream_iterator<int>(std::cout, " "));
std::cout << std::endl;
}
int main() {
show_contents(concatenate({1,2}, {3,4,5}, {6,7}));
show_contents(concatenate({8,9}));
show_contents(concatenate({9,8,7}, {6,5}, {4,3}, {2,1}));
}