I stumbled upon code like this:
void foo(T* bar); // Note: takes ownership of 'bar'.
foo(new T());
And now I wonder if there is any point in refactoring it to:
void foo(T* bar); // Note: takes ownership of 'bar'.
auto tempT = std::make_unique<T>();
foo(tempT.release());
- Is it more exception-safe?
- It certainly adds a little bit more clarity regarding the transfer of ownership, though calling 'new' from the argument list already makes that very clear by itself.
Note that I unfortunately can't change the signature of 'foo'.