3 ms·
But your exception-safe C++ code soon becomes bloated with shared_ptr and unique_ptr templates and copy ctors. Almost any C++ function, overloaded operator, or
by cpeterso 16y ago
But your exception-safe C++ code soon becomes bloated with shared_ptr and unique_ptr templates and copy ctors. Almost any C++ function, overloaded operator, or some implicit temporary object's ctor can throw an exception without warning. You must use RAII everywhere for every "resource".
Exception-safe RAII is pretty much an all-or-nothing affair.
- johnny531 16y agoNot sure what you mean with copy ctor bloat, but for your_flavor_of_smart_ptr, that's what the typedef keyword is for. A common idiom I use is to typedef a class's preferred smart-pointer as ptr_t within the class namespace. Passing them around now looks like: void some_function(my_class::ptr_t); Exception safe, clear semantics, & no bloat.
- blub 16y ago"But your exception-safe C++ code soon becomes bloated with shared_ptr and unique_ptr templates and copy ctors." You need to prove that, I think it's a bogus claim. There is no reason why good template code should be any larger than its hand-written equivalent. Any decent optimizing compiler will take care of the rest.