If the ownership model in your program is that the list “owns” the elements inside it, the second way (that is, with unique_ptr<T> ) is better. It allows C ++ to manage the resources of your list automatically, which is especially important in situations where the list is declared in the local scope, because you do not need to worry about leaving the scope prematurely.
source share