I'm trying to set a function that returns a vector of unique_ptrs, but I'm failing to do so. A simplified version of what I produced is the following:
#include <memory>
#include <vector>
std::vector<std::unique_ptr<int>>&& Foo()
{
std::vector<std::unique_ptr<int>> v;
v.emplace_back(std::make_unique<int>(1));
v.emplace_back(std::make_unique<int>(2));
v.emplace_back(std::make_unique<int>(3));
return std::move(v);
}
int main()
{
auto bar = Foo();
return 0;
}
However I'm getting a segmentation fault, once the value I return from the function Foo is assigned to the bar variable. What is the problem here?