I have two vectors:
std::vector<int> v1{ 1, 2, 3 };
std::vector<int> v2{ 4, 5, 6 };
I want to create an object of std::initializer_list which holds iterators to the first and last elements of above vectors.
I want to have a function with a variadic template:
template<class... Ts>
void foo(Ts... args)
and inside above function I want to unpack all arguments. So far I implemented:
template<class... Ts>
void foo(Ts... args)
{
std::initializer_list<std::vector<int>::iterator> il{
(std::begin(args), std::end(args))...
};
}
int main()
{
std::vector<int> v1{ 1, 2, 3 };
std::vector<int> v2{ 4, 5, 6 };
foo(v1, v2);
}
but it doesn't work as expected due to operator,. Current implementation creates initializer_list with two iterators. What I want in this case is to have an initializer_list with 4 iterators pointing to the first and one past the end element of these two vectors. I want it to be begin, end, begin, end.
You can make a new pack which is double the length:
Or consider if you need an
initializer_listat all. You might be able to use an array: