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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,24d1392c628fdfb6 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-04-13 13:10:02 PST Path: supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!dispose.news.demon.net!news.demon.co.uk!demon!pogner.demon.co.uk!zap!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: array Date: 13 Apr 2001 08:09:31 +0100 Organization: CodeFella Message-ID: References: <5s2B6.32267$ii5.3236241@afrodite.telenet-ops.be> NNTP-Posting-Host: localhost X-NNTP-Posting-Host: pogner.demon.co.uk:158.152.70.98 X-Trace: news.demon.co.uk 987192471 nnrp-13:17848 NO-IDENT pogner.demon.co.uk:158.152.70.98 X-Complaints-To: abuse@demon.net NNTP-Posting-Date: 13 Apr 2001 07:09:31 GMT X-Newsreader: Gnus v5.7/Emacs 20.7 Xref: supernews.google.com comp.lang.ada:6874 Date: 2001-04-13T07:09:31+00:00 List-Id: "Pieter Thysebaert" writes: > I've somehow been able to construct a binary tree (using nodes and > access types etc.) > > Now I was looking for a function that would allow me to convert the > contents of a tree into an array (and vice versa) I've found > something like arrays with variable range (I mean not fixed at > compile-time) Well I think that's what I found - does that thing > exist ? > > And if it does, how would one manipulate it (add/remove elements) It's certainly possible to work with unconstrained array types, you just need to be aware that the size of an instance of such a type is *not* variable; it can be fixed at initialization, though: type A is array (Integer range <>) of Integer; function Fun return A is Result : A (12 .. 34) := (others => 42); begin -- stuff return Result; end Fun; V : A := Fun; > Or are there data structures like C++ STL stuff (vector etc) > available ? The 20010325 release of the Booch Components contains a generic Copy feature: with Bc.Containers; generic type Item is private; with package Source is new BC.Containers (Item); type From is new Source.Container with private; with package Target is new BC.Containers (Item); type To is new Target.Container with private; with procedure Clear (The_Container : in out To) is <>; with procedure Add (To_The_Container : in out To; I : Item) is <>; procedure BC.Copy (Input : From; Output : in out To); Basically, you have a Source.From container type and a Target.To container type (clearly both containing the same sort of Item!). You need a procedure to Clear the Target.To container, and a procedure to Add Items to the Target.To container. procedure BC.Copy (Input : From; Output : in out To) is procedure Ins (I : Item; OK : out Boolean); pragma Inline (Ins); procedure Cp is new Source.Visit (Ins); procedure Ins (I : Item; OK : out Boolean) is begin Add (Output, I); OK := True; end Ins; It : Source.Iterator'Class := New_Iterator (Input); begin Clear (Output); Cp (It); end BC.Copy; The implementation Clears the the Target.To container and then iterates over the Source.From container, Adding each Item as it goes. -Simon