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!reader02.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: why "unconstrained subtype in component declaration" while said component given default value ? Date: Sun, 27 May 2018 08:07:03 +0100 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: h2725194.stratoserver.net; posting-host="72c963eeffe8f0f65beee661c7eaff64"; logging-data="5326"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18IdxkF1YSKnNgH/qw/nsGUO8JndTuNavY=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (darwin) Cancel-Lock: sha1:7ehEIQ6HMWoBmJJD+AKdaBawxnM= sha1:SgdIZ4i3mDGWg1NZicnEAaNf0wc= Xref: reader02.eternal-september.org comp.lang.ada:52717 Date: 2018-05-27T08:07:03+01:00 List-Id: Mehdi Saada <00120260a@gmail.com> writes: > Also, there's something that would be really cool, and I'm curious why > it could not be allowed: Why can't we provide a private constrained > subtype, of an inconstrained private type ? > > package III is > type A (<>) is private; > subtype B is A; -- should be a constrained subtype > private > function Donne_String (N : Positive) return String; > type A (N: Positive) is record > II : Integer; > Chaine : String(1..N) := Give_String(N); > end record; > end III; The Booch Components originally had the maximum length of a bounded container fixed at generic instantiation, which is a very limiting design. So as to avoid forcing all users to rework, I ended up with, for example, generic Maximum_Size : Positive; package BC.Containers.Collections.Bounded is type Unconstrained_Collection (Maximum_Size : Positive) is new Abstract_Collection with private; subtype Collection is Unconstrained_Collection (Maximum_Size => Maximum_Size); [...] function "=" (Left, Right : in Unconstrained_Collection) return Boolean; [...] procedure Insert (C : in out Unconstrained_Collection; Elem : Item); -- Add the item to the front of the collection.