Original Post
Is there any way I can print an initializer_list via << without being explicit about the fact that it is an initializer_list?
template<typename T>
void print(std::initializer_list<T> const& x)
{
for (auto it = x.begin(); it != x.end(); ++it)
{
// ...
}
}
template<typename T>
std::ostream& operator<<(std::ostream& os, std::initializer_list<T> const& x)
{
for (auto it = x.begin(); it != x.end(); ++it)
{
// ...
}
return os;
}
int main()
{
print( {4, 8, 15, 16, 23, 42} ); // works
std::cout << {4, 8, 15, 16, 23, 42}; // does not work
std::cout << std::initializer_list<int>( {4, 8, 15, 16, 23, 42} ); // too clumsy
}