2014/1/21 Johan Engelen <jbc.engelen@...2592...>:
How large do we expect this list to be?
I advise list<T> for now (moving onto unique_ptr when we make the switch
to C++11), just for the sake of simplicity and not unnecessarily relying
on external deps. I think there is a much higher chance of a dev knowing
the semantics of list<unique_ptr<T>> than boost::ptr_list<T>.
Boost include-only libraries are already a dependency, even for 2Geom.
The overhead of learning boost::ptr_list when you already know how to
use std::list is minimal compared to the overhead of writing
boilerplate destructor code on every object that contains an std::list
of pointers.
std::unique_ptr is only available in C++11 so we cannot use it yet,
and std::auto_ptr cannot be put into containers.
Here are some examples.
std::ptr_list<Object> list, list2
list.push_back(new Object(1, 2, 3));
list.push_back(new DerivedObject());
list.push_back(new Object(3, 2, 1));
list.erase(list.begin()); // calls desctructor
std::auto_ptr<Object> x = list.release(list.begin()); // if you want
to remove an object without destroying it
Regards, Krzysztof