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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Is this actually possible? Date: Thu, 12 Dec 2019 11:26:05 +0200 Organization: Tidorum Ltd Message-ID: References: <36d45c82-2a6b-4c60-baeb-1a4aef5189c7@googlegroups.com> <69c7677b-4aec-4db2-b240-de6b69f762b9@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net HkrWDeLefp4whg6A89sY9AB+eOOemGLwTGga5A0LHtxOPUSbB2 Cancel-Lock: sha1:RbmEsSYIARVx9Zr0GpU8bAVzfAA= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.2.1 In-Reply-To: Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:57714 Date: 2019-12-12T11:26:05+02:00 List-Id: On 2019-12-12 4:00, Randy Brukardt wrote: > "Dmitry A. Kazakov" wrote in message > news:qsrncj$u95$1@gioia.aioe.org... >> On 2019-12-11 22:12, Lucretia wrote: > ... >> Why? You must know all variants in order to compute the array element >> size. In Ada you cannot have it either: >> >> type Not_an_Array is array (Positive range <>) of T'Class; >> >> This is illegal. > > This is the purpose of the Bounded_Indefinite_Holders, because this is a > useful thing to do sometimes. > > package My_Holders is new Ada.Containers.Bounded_Indefinite_Holders > (T'Class, 100); > > type An_Array is array (Positive range <>) of My_Holders.Holder; > > Here, a Holder will hold up to 100 storage units. If some extension of > T'Class is bigger than that, setting the holder to a value of that extension > raises Program_Error. (As with most checks, this one can be suppressed, and > if it would fail and is suppressed, the program is erroneous - presumably > some other object memory would be overwritten. So don't do that. ;-) > > This is probably one of the best (and simplest) ideas of Ada 202x. Thanks to > Niklas Holsti for the original idea (although I think the actual resulting > package isn't much like Niklas' original idea). Thanks for the credit, Randy. I wanted a way to statically allocate a "max size" for class-wide objects, just as many compilers currently use an "allocate max size" for variant records with a default discriminant. My suggestion would also have needed the ability to change the tag of such a class-wide object, just as the discriminant of a variant-record object can be changed by assigning to the whole object. The wise heads of the ARG introduced the Bounded_Indefinite_Holder, giving just this effect: a bounded size, allowing static storage allocation, but also letting me change the tag by replacing the object being held with another object. My only worry about the present solution is if there is a lot of memory overhead in the Bounded_Indefinite_Holder. I don't see why there should be, but I guess I'll have to wait for an implementation to find out. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .