Is there a STL utility/algorithm to do delete *the_object_iterator;
on all the objects? So that I can clear()
safely? The STL container is a set
and the objects are pointers to C++ classes created with new
.
Boost seems to be the best solution. My goal was to avoid copy-construction on noncopyable classes.
Use a smart pointer to hold the class pointers
std::set<std::unique_ptr<MyClass> > mySet;
As far as I know, there is no standard algorithm to delete all objects. However, you can build up one easily:
template< typename T > invoke_delete( T* ptr ){ delete ptr; }
std::for_each( set.begin(), set.end(), &invoke_delete< set_value_type > );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With