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,2fa53692def716b5 X-Google-Attributes: gid103376,public From: "Robert I. Eachus" Subject: Re: null range from 1 element discrete type Date: 1999/11/19 Message-ID: <3835D5A0.F906D31D@mitre.org>#1/1 X-Deja-AN: 550726705 Content-Transfer-Encoding: 7bit References: X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@news.mitre.org X-Trace: top.mitre.org 943051825 20444 129.83.41.77 (19 Nov 1999 22:50:25 GMT) Organization: The MITRE Corporation Mime-Version: 1.0 NNTP-Posting-Date: 19 Nov 1999 22:50:25 GMT Newsgroups: comp.lang.ada Date: 1999-11-19T22:50:25+00:00 List-Id: Duncan Sands wrote: > > Suppose I have a discrete type (eg an enumeration type) T > containing just one element. I would like to define a subtype > with a null range. If T had more than one element, I could use > T'Last .. T'First, but this won't work here. How to get a null > range in this case? > > As you may guess, I have a generic package that takes a discrete > type parameter T, and I want it to work correctly in this degenerate > case. At some point the package declares an array type, eg > type A is array (T range <>) of Float; > and I want to declare a null slice of type A. At this point > I run into the above problem... Technically there is no "perfect" solution, as the compiler is allowed to choose a size of zero bits for such a type. But if the (sub)type is a generic formal type, you shouldn't have to worry about this possibility. Since you always want a null range try: T'Val(1) .. T'Val(0) Since 'Val returns the base type of T, as long as the base type of T contains at least one bit you are safe. -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...