You don't need move semantics to have RAII work. If you have a copyable type with a destructor where the cleanup should only happen once, then you already need some kind of refcount to only run the cleanup when the last copy is dropped. Either the refcount is in your own type, or you're wrapping another copyable refcounting type like shared_ptr.
Notice how I said "cleanup-via-destructor" rather than just "destructor", for this reason.
Re:C++ the Good Parts (2014)
by umanwizard on Tuesday October 06, 2020 @08:36PM
(#24704106)
You’re right, but one problem with c++ is that types are copiable by default and copies happen automatically and silently in many situations. So something like this is easy to get wrong.
What makes C++ flexible in practice is move semantics, which lets you move-return values, such that only the destructor call on the caller side is the one that matters.