Try the following code with native array, std::array and std::vector
typedef unique_ptr<int> UPtr;
UPtr[] f() // wrong, how to return a native array?
{
UPtr a[] = { UPtr(new int(1)), UPtr(new int(2)) };
return std::move(a);
}
std::array<UPtr, 2> g()
{
std::array<UPtr, 2> a = { UPtr(new int(1)), UPtr(new int(2)) }; // compile ok but run wrong, 1 and 2 are not assigned
return std::move(a); // wrong, call a deleted function
}
std::vector<UPtr> h()
{
std::vector<UPtr> a = { UPtr(new int(1)), UPtr(new int(2)) }; // wrong, call a deleted function
return std::move(a);
}
All failed. There are many problems here. How to fix them? Thanks a lot.