comp.lang.ada
 help / color / mirror / Atom feed
* How to properly clean up an extended, generic structure?
@ 2006-07-09 13:42 Peter C. Chapin
  2006-07-09 14:29 ` jimmaureenrogers
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Peter C. Chapin @ 2006-07-09 13:42 UTC (permalink / raw)


Hello! I'm working on improving my Ada skills by assigning myself little 
programming exercises and then solving them in Ada. I come from a C++ 
background so I tend to see the world in C++ terms. I realize that isn't 
necessarily helpful.

Right now I'm working on a generic package that implements splay trees. 
My generic parameters look like:

generic
    type Item_Type is private;
    with function "<"(L : Item_Type; R : Item_Type) return Boolean;
package Splay_Tree is ...


I've created a procedure Destroy_Tree that uses an instance of 
Ada.Unchecked_Deallocation to remove all the nodes in a given tree. 
Destroy_Tree is meant to be used when a tree is no longer needed and it 
serves the role of a destructor (using C++ terminology). It occurs to 
me, though, that Item_Type might have its own clean up needs. I assume 
that Unchecked_Deallocation knows nothing about that. Thus my code 
currently might be improperly cleaning up the Item_Types in each tree 
node. In C++ this is not a problem because deleting a node invokes the 
node's destructor (if there is one) so the issue is handled 
automatically. My question is how do I best deal with this in Ada?

I could pass a clean up procedure for Item_Types as another generic 
parameter. However, in cases where no such procedure is necessary (for 
example, when Item_Type is just Integer), such a solution seems awkward. 
Is there a nicer solution?

Peter



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2006-07-10  7:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-09 13:42 How to properly clean up an extended, generic structure? Peter C. Chapin
2006-07-09 14:29 ` jimmaureenrogers
2006-07-09 14:33 ` Ludovic Brenta
2006-07-09 16:21   ` Peter C. Chapin
2006-07-09 14:49 ` Björn Persson
2006-07-09 14:57 ` Georg Bauhaus
2006-07-09 19:46 ` Jeffrey R. Carter
2006-07-10  7:38   ` Jean-Pierre Rosen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox