Quick Q: How to initialize a const object (say vector) with complex initialization?—StackOverflow

Save to:
Instapaper Pocket Readability

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 a const vector of, say, random numbers? I couldn't think of a way to do it without deriving vector and doing the assignment in the constructor.

Add a Comment

You must sign in or register to add a comment.

Comments (0)

There are currently no comments on this entry.