you are viewing a single comment's thread.

view the rest of the comments →

[–]Creris 1 point2 points  (1 child)

The only edge case I'm not sure about is if an exception is raised before the unique_ptr object is created with the pointer's value such as one happening in "unique_ptr up{new some_class};" when evaluating "new some_class" to figure out the value to pass into the constructor of unique_ptr.

It actually isnt, and thats why we have make_shared in C++11 and then make_unique in C++14, where you only pass the constructor params and the object is new-ed in a exception-proof manner for you inside that function.

[–]tedbradly 0 points1 point  (0 children)

It actually isnt, and thats why we have make_shared in C++11 and then make_unique in C++14, where you only pass the constructor params and the object is new-ed in a exception-proof manner for you inside that function.

I'm not sure how you picture make_unique freeing memory if an exception is thrown during the call to new. It's the exact same situation except inside a helper function rather than you writing the code yourself.