From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: array from static predicate on enumerated type Date: Fri, 12 Mar 2021 23:16:29 +0100 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <89128f73-fcc5-4e57-8067-d09877ba0211n@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 12 Mar 2021 22:16:30 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="29e3787fdea1dfab45c77af10c01c39f"; logging-data="17347"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19jumvzH35EkgORYuCQPZRlxfP94rQ2/hQ=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 Cancel-Lock: sha1:2Q/J4Nw5OZQnwpm1CR11R4TC6fc= In-Reply-To: <89128f73-fcc5-4e57-8067-d09877ba0211n@googlegroups.com> Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:61505 List-Id: On 3/12/21 9:49 PM, Matt Borchers wrote: > Say, for example, I define a static predicate on a sub-type of an enumerated type, like: > > type LETTERS is ( A, B, C, D, E, F, G, H, I , J, K ); > > subtype CURVED is LETTERS > with Static_Predicate CURVED in B | C | D | G | J; > > What I want is an array over CURVED (using CURVED as the index), but since attributes 'First and 'Last (and thus 'Range) is not allowed, this cannot be done. > > Has anybody come up with a clever data structure to make sub-types with predicates easy and sensible for indexing (not iterating)? > > I only need read access ... It sounds as if you want a map, for which one of the map containers in the standard library would be appropriate. -- Jeff Carter "[I]t is foolish to polish a program beyond the point of diminishing returns, but most programmers do too little revision; they are satisfied too early." Elements of Programming Style 189