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,7b668a769fbfcee0 X-Google-Attributes: gid103376,public From: steve.folly@rdel.co.uk (Steve Folly) Subject: Re: array(enumeration) Date: 2000/07/20 Message-ID: <3976f010.17369105@news.rrds.co.uk>#1/1 X-Deja-AN: 648588237 References: X-Complaints-To: postmaster@rdel.co.uk X-Trace: rdel.co.uk 964096555 26489 172.16.115.146 (20 Jul 2000 12:35:55 GMT) Organization: RDEL NNTP-Posting-Date: 20 Jul 2000 12:35:55 GMT Newsgroups: comp.lang.ada Date: 2000-07-20T12:35:55+00:00 List-Id: On Wed, 19 Jul 2000 17:13:44 +0100 (WEST), Mario Amado Alves did clatter that keyboard and type: >How do I define an array type indexed by an enumeration type? > > type Array_Type is array(<>) of Some_Type; > -- /|\ > -- | > -- compiler says identifier expected here > > type Enumeration_Type is (A, B, C); > type Another_Enumeration_Type is (X, Y, Z); > > A_Thing: Array_Type(Enumeration_Type) := ( > A => ... , > B => ... , > C => ... ); > > Another_Thing: Array_Type(Another_Emuneration_Type) := ( > X => ... , > Y => ... , > Z => ... ); > >This makes sense to me, but does not compile. So how do I code the idea? > You have to create separate array types for each enumeration... type Enum_Type is (A, B, C); type Enum_Array is array (Enum_Type) of Some_Type; type Another_Enum_Type is (X, Y, Z); type Another_Enum_Array is array (Another_Enum_Type) of Some_Type; A_Thing : Enum_Array := .... Another_Thing : Another_Enum_Array := ... OK, the names get a bit long winded, but you can easily sort that out! I suppose you could make a generic package and export the array type from it, but I really can't see any advantage in doing it. More (unnecessary) code, for a start! generic type Index is (<>); type Item is private; package Generic_Array is type Array is array (Index) of Item; end Generic_Array; and then... package Enum_Array is new Generic_Array(Index => Enumeration_Type, Item => Some_Type); A_Thing : Enum_Array.Array := .... If were thinking of maybe adding a few subprograms to do clever things to the array (iterators, maybe), then maybe you could go down this route, otherwise I would suggest just sticking to plain types. Don't overcomplicate things! -- Regards, Steve Folly.