I\'m trying to use brace-enclosed initializer lists in a variadic template function, but the compiler complains... am I asking too much or did I do something wrong?
This is a rough attempt at what you want...
#include
#include
struct Bracy {
Bracy(int x, int y) {}
};
struct Test {
void consumeOne(std::initializer_list) { std::cout << "initializer list version (Bracy?)\n"; /* Bracy? */}
void consumeOne(int) { std::cout << "int version\n"; }
template
void consume(T t) { consumeOne(t); }
template
void consume(T first, Args ... args) {
consumeOne(first);
consume(args...);
}
template
Test(Args ... args) {
consume(args...);
}
};
int
main(int argc, char** argv) {
Test(1, std::initializer_list{1,2}, 2, 3, std::initializer_list{1,2});
return 0;
}
output: int version
initializer list version (Bracy?)
int version
int version
initializer list version (Bracy?)