You can avoid directly specifying the type of iterator, which should lead to cleaner code:
void f(std::initializer_list<int> nums)
{
for (auto x : nums) {
std::cout << x << '\n';
}
std::copy(begin(nums), end(nums), std::ostream_iterator(std::cout, "\n"));
}
The range for loops is supported in GCC 4.6 . (Any problem causing their foreach loops informally?)
The inclusion of a <iterator> may be required for std :: begin and std :: end, although some headers guarantee that they are declared (24.6.5, N3092).
Roger Pate
source
share