From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2ce943dcc1eb3f9c,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!news-out.readnews.com!news-xxxfer.readnews.com!not-for-mail Date: Sun, 09 Jul 2006 09:42:18 -0400 From: "Peter C. Chapin" User-Agent: Thunderbird 1.5.0.4 (Windows/20060516) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: How to properly clean up an extended, generic structure? Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <44b107b7$0$3629$4d3efbfe@news.sover.net> Organization: SoVerNet (sover.net) NNTP-Posting-Host: ddc41c50.news.sover.net X-Trace: DXC=_5QlD_5JS87feRiJg>nP^7K6_LM2JZB_36>gSWXGK7I5:WUUlR<856?O^R6QJ^I@:8 X-Complaints-To: abuse@sover.net Xref: g2news2.google.com comp.lang.ada:5574 Date: 2006-07-09T09:42:18-04:00 List-Id: 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