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: border2.nntp.dca3.giganews.com!backlog4.nntp.dca3.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "J-P. Rosen" Newsgroups: comp.lang.ada Subject: Re: How to declare a generic formal type "covered" by another? Date: Thu, 01 May 2014 09:09:39 +0200 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Injection-Date: Thu, 1 May 2014 07:09:37 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="214e2226c9a2cb4f71713357be0d6925"; logging-data="23916"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+aFqdsR0AL7g/PKfwsA1AU" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 In-Reply-To: Cancel-Lock: sha1:2PWXfiIf7n6GpRcGtbvle0Q6+bc= X-Enigmail-Version: 1.6 X-Original-Bytes: 3517 Xref: number.nntp.dca.giganews.com comp.lang.ada:186179 Date: 2014-05-01T09:09:39+02:00 List-Id: Le 01/05/2014 08:54, Natasha Kerensikova a écrit : > Hello, > > this a general question stemmed by a new idea on how to solve the > problem exposed in my previous thread (I wouldn't have started a new > thread if I knew my newsreader well enough to do so). > > I'm not good enough with language-lawyer vocabulary (hence the quotes > around "covered" in the subject), so I'll write it mostly in Ada. > Basically I want two generic formal T and S, so that I can write: > > Access_To_T_Value := new S; > > I too the verb "cover" from 4.8(3/1) to mean this relationship between S > and T, but I'm not sure how correct it is. > > The context would look like that: > > generic > type T (<>) is limited private; > package References is > > type Exposed_Type is tagged private; > > generic > type S is adequately declared; > function Allocate return Exposed_Type; > > private > type Internal_Access is access T; > type Exposed_Type is new Ada.Finalization.Controlled with record > Value : Internal_Access; > end record; > end References; > > package body References is > function Allocate return Exposed_Type is > begin > return (Ada.Finalization.Controlled with > Value => new S); > end Allocate; > end References; > > > So S would have to be a concrete constrained type, but looking at the > alternatives for "formal_type_definition", I can't see anything that > covers both S being a constrained version of T, and S being a concrete > tagged type belonging to class-wide T. > > Is it possible, or am I hitting a limit of Ada generics? 1) There is nothing here that requires T to be tagged 2) You can say that S must be derived from T: type S is new T; (non tagged type) type S is new T with private; (tagged type) 3) There is no way to say that S must be constrained, because being constrained is a matter of subtype, and only types matter for generics. The best way to constrain an allocator is by providing an initial value, that you could pass as a parameter to Allocate f.e. -- J-P. Rosen Adalog 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00 http://www.adalog.fr