Algorithm solution:
std::generate(numbers.begin(), numbers.end(), rand);
Range-based for-loop solution:
for (int& x : numbers) x = rand();
Why would I want to use the more verbose
std::generate
over range-based for-loops in C++11?
Update from the Ranges Study Group
In December, we announced the opening of the SG9 (Ranges) mailing list. Since then, the activity on it has been nothing short of amazing, and the discussion is of a markedly high quality. Ranges promise a improvement in usability, power, and safety for the STL. If you have ever wanted to see how the C++ Standardization Committee crafts the future of C++, sidle on over to the Ranges group and learn about the future of the STL from many of the people who have helped shape it since its inception. Watch tomorrow's C++ take shape today, and maybe help shape it yourself.
Read the list archives here, or sign up to get the blow-by-blow here.
P.S. You can start using (one implementation of) Ranges today over at Boost (see Boost.Range's docs).