What is the best way of passing and transferring ownership of a vector and it's data?
In an ideal world, it would work something like this:
std::vector<int>& SpitAVector(int input)
{
std::vector<int> result;
result.push_back(input);
return result;
}
int main()
{
std::vector<int> myvec;
myvec = SpitAVector(60);
std::cout << (int)myvec[0] << std::endl; //Outputs 60
}
This doesn't work, since I'm returning a reference to a local variable.
Is it possible to use boost::unique_ptr
or boost::shared_ptr
to handle this vector output? (Can't use C++11's unique_ptr!)