Currently I'm initializing a list
/vector
etc. like this:
std::vector<int> vec_rand(target_size);
std::generate(vec_rand.begin(), vec_rand.end(), std::rand);
.. as already shown here. std::rand
is just an example - it could be any function.
I was just wondering if there's a way to create/resize a container and initialize it's values with arbitrary values at the same time.
I know I don't have to expect a big performance boost but It would be nicer (and less verbose) to have s.th. like
vector<int> my_list(10, std::rand);
or
my_list.resize(target_size, std::rand);
rather than to first resize()
with default values and than overwrite them with the desired content.