I recently switched to C++11 and I'm trying to get used to good practices there. What I end up dealing with very often is something like:
class Owner
{
private:
vector<unique_ptr<HeavyResource>> _vectorOfHeavyResources;
public:
virtual const vector<const HeavyResource*>* GetVectorOfResources() const;
};
This requires me to do something like adding a _returnableVector and translating the source vectors to be able to return it later on:
_returnableVector = vector<HeavyResource*>;
for (int i=0; i< _vectorOfHeavyResources.size(); i++)
{
_returnableVector.push_back(_vectorOfHeavyResources[i].get());
}
Has anyone noticed similar problem? What are your thoughts and solutions? Am I getting the whole ownership idea right here?
UPDATE:
Heres another thing:
What if one class returns a result of some processing as vector<unique_ptr<HeavyResource>>
(it passes the ownership of the results to the caller), and it is supposed to be used for some subsequent processing:
vector<unique_ptr<HeavyResource>> partialResult = _processor1.Process();
// translation
auto result = _processor2.Process(translatedPartialResult); // the argument of process is vector<const HeavyResource*>