When writing f({1,2})
you are using list initialization.
If you want to pass the initializer list {1,2}
to a function as is you can do it like this:
#include <initializer_list>
#include <iostream>
template <typename T>
int f(std::initializer_list<T> a) {
for(const T& x : a) {
std::cout << x << ", " << std::endl; // do something with the element
}
return 0;
}
int main() {
f({1,2});
}