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-Thread: 103376,115cdbb394b3e615 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!news.cs.univ-paris8.fr!newsfeed.vmunix.org!newsfeed.stueberl.de!newsr1.ipcore.viaginterkom.de!news-peer1!btnet-feed5!btnet!news.btopenworld.com!not-for-mail From: Martin Dowie Newsgroups: comp.lang.ada Subject: Re: Why can't you create a out of order subtype? Date: Wed, 2 Feb 2005 19:35:22 +0000 (UTC) Organization: BT Openworld Message-ID: References: <1107301914.648240.237290@g14g2000cwa.googlegroups.com> NNTP-Posting-Host: host81-154-188-69.range81-154.btcentralplus.com Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: titan.btinternet.com 1107372922 24309 81.154.188.69 (2 Feb 2005 19:35:22 GMT) X-Complaints-To: news-complaints@lists.btinternet.com NNTP-Posting-Date: Wed, 2 Feb 2005 19:35:22 +0000 (UTC) In-Reply-To: X-Accept-Language: en-us, en User-Agent: Mozilla Thunderbird 1.0RC1 (Windows/20041201) Xref: g2news1.google.com comp.lang.ada:8136 Date: 2005-02-02T19:35:22+00:00 List-Id: Marius Amado Alves wrote: >> ... >> >>> Another option that I think is much, much worse then the boolean array >>> would be create an overloaded type... >>> type msg is ( msg_a, msg_b, msg_c, msg_d, msg_e); >>> type vowelmsg ( msg_a, msg_e); >>> But as you know, msg.msg_e = 4 and vowelmsg.msg_e = 1 so an unchecked >>> conversion is wrong on so many levels. >> >> >> Yes, this may be worse, but you can at least get Unchecked_Conversion >> to work: >> >> for Vowelmsg use (Msg_A => 0, Msg_E => 4); >> for Vowelmsg'Size use Msg'Size; >> >> This would still be a run-time check:... > > > For run-time I find the "Value of Image" idiom a better one. It's > readily available. No Unchecked_Conversion required. > > declare > M : Msg := Whatever; > V : Vowelmsg; > begin > V := Vowelmsg'Value (Msg'Image (M)); > -- if control reaches here then M is a vowel > exception > when Constraint_Error => -- M is not a vowel > end; That's very, very, very slow... Cheers -- Martin