Quick Q: How to initialize a const object (say vector) with complex initialization? -- StackOverflow
Quick A: With a lambda function. Try
const mytype myobj{ []{ /* compute value */ return value; } }
.
How would you initialize a const vector of function results using C++11?
Is it possible to use something like
generate_n
to create aconst vector
of, say, random numbers? I couldn't think of a way to do it without derivingvector
and doing the assignment in the constructor.