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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.58.107.203 with SMTP id he11mr840632veb.12.1400807119697; Thu, 22 May 2014 18:05:19 -0700 (PDT) X-Received: by 10.50.66.129 with SMTP id f1mr6845igt.13.1400807119587; Thu, 22 May 2014 18:05:19 -0700 (PDT) Path: border1.nntp.dca.giganews.com!nntp.giganews.com!hl10no3913483igb.0!news-out.google.com!qf4ni5721igc.0!nntp.google.com!c1no14338431igq.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 22 May 2014 18:05:19 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=KSa2aQoAAACOxnC0usBJYX8NE3x3a1Xq NNTP-Posting-Host: 66.126.103.122 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Empty Bounded Containers From: Adam Beneschan Injection-Date: Fri, 23 May 2014 01:05:19 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: number.nntp.dca.giganews.com comp.lang.ada:186567 Date: 2014-05-22T18:05:19-07:00 List-Id: On Thursday, May 22, 2014 5:20:51 PM UTC-7, sbelm...@gmail.com wrote: > Hi, >=20 > In the sundry Ada distributions I have around, the "empty" bounded contai= ners are fully defined as having a capacity of zero, e.g. >=20 > Empty_Vector : constant Vector :=3D (Capacity =3D> 0, others =3D> <>); >=20 > which is not intuitively what I would assume. For instance, the followin= g line: >=20 > x : BC.Vector (Capacity =3D> 42) :=3D BC.Empty_Vector; >=20 > implies an container with a capacity of 42 initialized to a length of zer= o, but it of course throws a constraint error. In fact, there really doesn= 't seem to be any valid use of the Empty_Vector (et al), since the actual c= apacity is hidden in the private part. I don't understand this. If you write a procedure that takes a Vector as i= nput, it is often very handy to give callers the ability to call your proce= dure with Empty_Vector as the actual parameter. > The LRM just says it should be the same between the two without addressi= ng the discriminant, which isn't much help. =20 >=20 > Moreover, the wording seems to legally contradict itself, since by statin= g "If an object of type Vector is not otherwise initialized, it is initiali= zed to the same value as Empty_Vector" it would seem to imply that=20 >=20 > x : BC.Vector (Capacity =3D> 42); >=20 > ought to use the values from the Empty_Container, causing the same error,= leaving no actual way to ever have any bounded containers at all. >=20 > Does anyone know what the intention actually is? I think the RM wording seems a bit sloppy, but that "value" in this context= refers to the things that are conceptually contained in the container (i.e= . the length, and the elements at each index), and not to the representatio= n. I'd consider "capacity" to be part of the container's representation, n= ot of its value. Anyway, I think you're overthinking here (*). The wordin= g just means it's initialized to a container with no elements and length 0. The assignment operator in Ada, however, isn't set up to copy "values" in a= way that could change the representation, and it can't be overloaded the w= ay assignment can in C++. (This is actually a pretty cool feature of C++, = as long as your program works perfectly the first time and never needs to b= e debugged or changed.) What might be useful, that I don't see in the Boun= ded_Vectors spec, is a function that would return a vector with the same el= ements as an input parameter, but with a different capacity, e.g. x : BC.Vector :=3D BC.Copy_And_Change_Capacity (BC.Empty_Vector, Capacity = =3D> 42); It wouldn't be all that useful for Empty_Vector since that's the default in= itialization anyway, but it conceivably could be useful in other cases. (*) Yeah, I know, pot, kettle. -- Adam