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: What's the difference between constexpr and const? -- StackOverflow
C++11's const
and constexpr
have somewhat different purposes, but similar names. Hence the natural question:
Difference between
constexpr
andconst
What's the difference between
constexpr
andconst
?
- When can I use only one of them?
- When can I use both and how should I choose one?