jeudi 24 août 2017

Move std::vector

Somtimes there is a case that we have a factory that produces a vector of std::unique_ptr and later on we would like share these pointers between classes/threads/you name it. So it would be desirable to use std::shared_ptr instead. There is a way of course to convert std::uniqe_ptr to std::shared_ptr

std::shared_ptr<int> sharedV;
std::unique_ptr<int> uniqueV(new int(2));

sharedV = std::move(uniqueV);

So is there any straightforward way to do such thing with std collections?

Aucun commentaire:

Enregistrer un commentaire