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?
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?
Add a Comment
Comments are closed.