jeudi 9 février 2023

How can I determine functions' parameter and return value for std::unique_ptr? [closed]

These three pieces of code below seem to convey almost the same thing(i.e. change the outside resource in the function), and how can I determine the exact way?

std::unique_ptr<int> test(std::unique_ptr<int> ptr)
{
   // some op
   return ptr;
}
std::unique_ptr<int>&& test(std::unique_ptr<int>&& ptr)
{
   // some op
   return std::move(ptr);
}
void test(std::unique_ptr<int>& ptr)
{
   // some op
   return;
}

Besides, this seems to be a common problem for moveable classes.

Aucun commentaire:

Enregistrer un commentaire