Everyone creates std::vector
from std::initializer_list
, but what about the other way around?
eg. if you use a std::initializer_list
If you don't mind copies, then I think something like this would work:
template
using iterator_init_list = std::initializer_list::value_type>;
template
iterator_init_list to_initializer_list(Iterator start, Iterator last, Ts... xs)
{
if (start == last) return iterator_init_list{xs...};
else return to_initializer_list(start+1, last, xs..., *start);
}