So I can do this:
for(const auto i : { 13, 42 }) cout << i << ' ';
But I can't do this:
copy_n(cbegin({ 13, 42 }), 2, ostream_iterator<int>(cout, " "));
It gives me the error:
error: no matching function for call to
cbegin(<brace-enclosed initializer list>)
What is it about the for
-statement that allows this but not the cbegin
function?
Edit:
It appears that the problem is that my initializer_list
isn't being treated as an initializer_list
, because if I do this it works:
copy_n(cbegin(initializer_list<int>{ 13, 42 }), 2, ostream_iterator<int>(cout, " "));