Re: [gtk-list] Re: Gtk--: G_List quirks



Guillaume Laurent wrote:
> 
> All I can add to the two previous replies is that I very strongly
> suggest you learn about the STL (I have a few pointers among my
> bookmarks on my homepage). You are missing something indeed. The only
> valid reason for not using the STL when writing C++ today would be
> being forced to use an obsolete compiler.
> 

Well, there are other good reasons for not using them. Offhand, I can
think of two:

1) with many of the containers defined by STL, calling erase against an
iterator into that container may invalidate other iterators active on
that container (STL list is a notable exception to this). For some
applications, this may be most inconvenient.

2) there are problems with exception safety w.r.t. auto_ptrs. If an
exception is thrown while an item is being inserted into an STL
container (say memory allocation failure, or whatever), the contents of
the container are guaranteed to be in the same state after the exception
as they were before the call that provoked it. However, there are no
guarantees about what temporary assignments have taken place as part of
the call, and with an auto_ptr, assignment invalidates the rhs. So as
part of the stack unwinding induced by the exception throw, destruction
of the auto_ptr temp deletes the object that the argument auto_ptr was
pointing to. So the contents of the container escape unharmed from the
exception, but the poor method argument is not so lucky...

Sorry that this was so off-topic, and I'm not saying that one should
never use STL, only that there are times when it is not a good idea.

Regards
M.Beach



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]