initlist.cpp

The following code example is taken from the book
C++ Templates - The Complete Guide, 2nd Edition
by David Vandevoorde, Nicolai M. Josuttis, and Douglas Gregor,
Addison-Wesley, 2017
© Copyright David Vandevoorde, Nicolai M. Josuttis, Douglas Gregor 2017


#include <initializer_list>

template<typename T> void f(std::initializer_list<T>);

int main()
{
  f({2, 3, 5, 7, 9});                // OK: T is deduced to int
  f({'a', 'e', 'i', 'o', 'u', 42});  // ERROR: T deduced to both char and int
}