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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,80a67c84f8039eab,start X-Google-Attributes: gid103376,public From: Brian Rogoff Subject: Some questions on a library design Date: 1997/06/16 Message-ID: #1/1 X-Deja-AN: 248926885 Newsgroups: comp.lang.ada Date: 1997-06-16T00:00:00+00:00 List-Id: Hi, In the process of writing a collection library for Ada I have encountered a few stumbling blocks that I hope can be removed. The library is rather like the C++ STL, and so I avoid dynamic dispatching *completely*. I have also avoided tagged types although that is not strictly necessary. One of the containers in the library is a generic set, whose specification looks like this generic type Element_Type is private; with function "<" ( Left, Right : Element_Type ) return Boolean is <>; package AGL.Sets is type Set_Type is private; type Value_Type is private; function Is_Member ( Set : Set_Type; Key : Value_Type ) return Boolean; ... etc. ... end AGL.Sets; and a child package Iterators which instantiates its own textually nested packages corresponding to the kinds of traversal it supports generic package AGL.Sets.Iterators is type Iterator_Type is private; function Start ( Set : Set_Type ) return Iterator_Type; function Finish ( Set : Set_Type ) return Iterator_Type; ... etc. ... package Forward_Iterators is new AGL.Forward_Iterators(Value_Type, Iterator_Type, Value_Ptr, Next, Get_Value, Set_Value, Get_Pointer); package Bidirectional_Iterators is new AGL.Bidirectional_Iterators(Value_Type,Iterator_Type,Value_Ptr, Next,Prev,Get_Value,Set_Value, Get_Pointer,"="); end AGL.Sets.Iterators; The packages AGL.Whatever_Iterators are null bodied generic signature packages, and their instantiations in the Whatever_Container.Iterators package are "plugged" in to the various algorithms which only know about the iterator signature. I have a Red_Black_Trees package which also has an Iterators child package, and I would like to use them to implement the Sets/Sets.Iterators (and of course Maps/Maps.Iterators, Multisets/Multisets.Iterators, etc.). I'd like for aesthetic reasons (;-)) to keep this implementation choice private (I'll have a Splay_Trees package any time now). However, I am having a bit of trouble figuring out how to do this; so far I just declare the Red_Black_Trees package in the public part of Sets' spec, and do the same with Red_Black_Trees.Iterators in Sets.Iterators, like so: generic type Element_Type is private; with function "<" ( Left, Right : Element_Type ) return Boolean is <>; package AGL.Sets is -- Our Set_Type is implemented as a Red_Black_Tree package Trees is new AGL.Red_Black_Trees( Element_Type => Element_Type, Insert_Always => False, "<" => "<" ); subtype Set_Type is Trees.Tree_Type; subtype Value_Type is Trees.Value_Type; subtype Value_Ptr is Trees.Value_Ptr; ... etc. ... end AGL.Sets; generic package AGL.Sets.Iterators is package Tree_Iterators is new Trees.Iterators; subtype Iterator_Type is Tree_Iterators.Iterator_Type; ... etc. ... end AGL.Sets.Iterators; I find it inelegant in that I'd prefer that representation information be restricted to the private part of a package, even though that seems to be necessary in order to instantiate the signature packages in Sets.Iterators. Any suggestions on how to do this better? Also, I thought it would be cool if I could do a partial instantiation of a generic package to create a new generic package with fewer parameters, like generic package Sets is new Red_Black_Trees ( Insert_Always => False ); generic package Multisets is new Red_Black_Trees ( Insert_Always => True ); Am I missing something, i.e., is there a good approximation to this functionality in Ada? -- Brian