From: steve.folly@rdel.co.uk (Steve Folly)
Subject: Re: array(enumeration)
Date: 2000/07/20
Date: 2000-07-20T12:35:55+00:00 [thread overview]
Message-ID: <3976f010.17369105@news.rrds.co.uk> (raw)
In-Reply-To: Pine.LNX.4.10.10007191643160.863-100000@lexis.di.fct.unl.pt
On Wed, 19 Jul 2000 17:13:44 +0100 (WEST), Mario Amado Alves <maa@di.fct.unl.pt>
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.
next prev parent reply other threads:[~2000-07-20 0:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-07-19 0:00 array(enumeration) Mario Amado Alves
2000-07-20 0:00 ` Steve Folly [this message]
2000-07-20 0:00 ` array(enumeration) Philip Anderson
2000-07-20 0:00 ` array(enumeration) Frode Tenneboe
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox