On 21-1-2014 18:54, Krzysztof KosiĆski wrote:
2014/1/21 Martin Owens <doctormo@...400...>:
> Ah man, I just got it working with GSList and boost looks like a dogs
> breakfast of spaghetti code. Do I /have/ to use boost or can std::list
> do the job too? (not example in the code of boost::ptr_list, very unsafe
> to try and implement)
I'm not sure what you mean by boost::ptr_list being unsafe.
boost::ptr_list<T> works almost exactly like a
std::list<std::unique_ptr<T>>, but iterators dereference to object
references.
boost::intrusive::list allows you to compute an iterator to the
element from the element itself in constant time, so it is very useful
if an object needs to remove itself from the list.
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>.
Please also document that the pointers in the list are owning pointers
(i.e. the SPDoc owns its children and deletes them when it itself is
deleted).
regards,
Johan