1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #include <vector> void f(std::vector<double> v); template <class T> void g(T&& t) { f(t); } int m() { f({1, 2}); // that's OK g({1, 2}); // that's not } |
I2luY2x1ZGUgPHZlY3Rvcj4KCnZvaWQgZihzdGQ6OnZlY3Rvcjxkb3VibGU+IHYpOwoKdGVtcGxhdGUgPGNsYXNzIFQ+CnZvaWQgZyhUJiYgdCkKewogIGYodCk7Cn0KCmludCBtKCkKewogIGYoezEsIDJ9KTsgLy8gdGhhdCdzIE9LCiAgZyh7MSwgMn0pOyAvLyB0aGF0J3Mgbm90Cn0K
prog.cpp: In function 'int m()': prog.cpp:14:11: warning: deducing 'T' as 'std::initializer_list<int>' prog.cpp:6:6: warning: in call to 'void g(T&&) [with T = std::initializer_list<int>]' prog.cpp:14:11: warning: (you can disable this with -fno-deduce-init-list) prog.cpp: In function 'void g(T&&) [with T = std::initializer_list<int>]': prog.cpp:14:11: instantiated from here prog.cpp:8:3: error: conversion from 'std::initializer_list<int>' to non-scalar type 'std::vector<double>' requested
-
result: Compilation error (maybe you wish to see an example for C++11)


