Consider the function:
template<typename T>
void printme(T&& t) {
for (auto i : t)
std::cout << i;
}
or any other function that expects one parameter with a begin()/end() - enabled type.
Why is the following illegal?
printme({'a', 'b', 'c'});
When all these are legitimate:
printme(std::vector<char>({'a', 'b', 'c'}));
printme(std::string("abc"));
printme(std::array<char, 3> {'a', 'b', 'c'});
We can even write this:
const auto il = {'a', 'b', 'c'};
printme(il);
or
printme<std::initializer_list<char>>({'a', 'b', 'c'});
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…