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!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Jeffrey Carter Newsgroups: comp.lang.ada Subject: Re: How to declare a generic formal type "covered" by another? Date: Thu, 01 May 2014 13:59:35 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 1 May 2014 20:59:37 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="42ea65963a295dd28559459f9f96c6a5"; logging-data="599"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19160+l+LTXFk5+FHGKeubE9Itavm5JFSQ=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 In-Reply-To: Cancel-Lock: sha1:vWTW1GUnjSv9GvjVxSvxKJRCohc= Xref: news.eternal-september.org comp.lang.ada:19639 Date: 2014-05-01T13:59:35-07:00 List-Id: On 05/01/2014 12:33 AM, Natasha Kerensikova wrote: > > Well maybe the problem here is my limited vocabulary. I used the word > "constrained" there only to mean "Something := new S" or "Variable : S;" > are both valid, i.e. objects of that type can be created without > further information. There must be some way to express that in generics. As Rosen has pointed out, this is the definite/indefinite idea, expressed in generic formals as lacking/having unknown discriminants ["(<>)"]. Most definite subtypes are constrained, and most indefinite, unconstrained, but that's not always the case. Consider subtype VSI is Integer range 0 .. 255; type VS (Length : VSI := 0) is record Value : String (1 .. Length); end record; VS is definite, because you can say S : VS; but it's also unconstrained, because you can change the discriminant: S := (Length => 1, Value => "A"); S := (Length => 2, Value => "Hi"); For your uses, perhaps you should consider something like generic -- GP type T (<>) is limited private; package GP is type T_Access is access all T; type Ref is private; generic -- F with function Allocate return T_Access; function Allocate return Ref; ... end GP; Most smart-pointer packages expose the access type; see, for example, http://www.oopweb.com/Ada/Documents/AdaLinux/Volume/18.html http://www.adacore.com/adaanswers/gems/gem-97-reference-counting-in-ada-part-1/ HTH. -- Jeff Carter "C++ is like jamming a helicopter inside a Miata and expecting some sort of improvement." Drew Olbrich 51