No, but this is what std::generate
is for.
Instead of being given a single value that's copied throughout the target range, std::generate
is given a "generator" function that creates each value as needed.
So, probably, something like this:
std::unique_ptr<int> ar[3];
std::generate(
std::begin(ar),
std::end(ar),
[]() { return std::make_unique<int>(1); }
);
I haven't tried it, and don't know whether you need to fiddle with it at all in order to avoid problems stemming from non-copyability. Hopefully move semantics are enough.
(Of course, in C++11, you will need your own make_unique
function.)
By the way, your .begin()
and .end()
were wrong (arrays don't have member functions), so (thanks to a reminder from songyuanyao) I have corrected those.