Re: [boost] Is there any interest in a library that provides containers with virtual destructors?

At 21:52 2005-10-26, Matt Calabrese wrote:
On 10/26/05, Victor A. Wagner Jr. <vawjr@rudbek.com> wrote:
perhaps some other paragraph? this doesn't address anything about derived objects.
Just look 2 paragraphs further:
5.3.5 paragraph 3
"In the first alternative (delete object), if the static type of the operand is different from its dynamic type, the static type shall be a base class of the operand's dynamic type and the static type shall have a virtual destructor or the behavior is undefined." ...
indeed, but there is no dynamic type vs static type in the example.
The paragraph then goes further to talk about arrays.
As for interest in the STL containers with virtual destructors, I'd personally say no.
I didn't suggest them, I'm arguing that for the example given they aren't necessary
I've never encountered a situation where it would be useful or at least useful and better than other alternatives. Anyway, the desire for a virtual destructor could exist with any type. If someone wants virtual destructors for STL containers, then what next? multi_array with virtual destructors? graphs? Forgive me if that sounds like a slippery slope argument, but really I see no logic as to why one would want virtual destructors for STL containers yet not any other types. You can use the same type of argument for any type you can think of -- "I want to derive from the type and then add functionality, but want to delete it via a pointer to the base class".
I have never said such. I don't know where you got the idea I had.
Does this mean that all types should have one version with virtual destructors, and one without? Definately not. I just don't see why someone would want to make the exception for STL containers.
-- -Matt Calabrese _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Victor A. Wagner Jr. http://rudbek.com The five most dangerous words in the English language: "There oughta be a law"

On 10/27/05, Victor A. Wagner Jr. <vawjr@rudbek.com> wrote:
indeed, but there is no dynamic type vs static type in the example.
If you have a virtual_vector<person>* which points to an instance of people, and you call delete with that pointer as an operand, you have undefined behavior unless virtual_vector<person> has a virtual destructor since virtual_vector<person> is the static type and people is the dynamic type. Whether the base or derived type has a trivial or non-trivial destructor doesn't change that. The behavior is always undefined. If you were talking about just deleting a people pointer pointing to a people object, of course there would be no need for a virtual destructor, though if that's all that you're talking about, I still don't see why you are differentiating between trivial and nontrivial destructors. Whether or not the destructor is trivial or non-trivial still makes no difference, just like in the previous example. On 10/27/05, Victor A. Wagner Jr. <vawjr@rudbek.com> wrote:
I didn't suggest them, I'm arguing that for the example given they aren't necessary
This was targeted at the original poster who asked if there is interest. It wasn't intended for you. -- -Matt Calabrese
participants (2)
-
Matt Calabrese
-
Victor A. Wagner Jr.