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?
Quick Q: Does the range-based for loop make std algorithms obsolete? -- StackOverflow
Here's a fine question from StackOverflow[C++11]. Click through for some fine answers.
Does the Range-based for Loop Make std Algorithms Obsolete?