From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: derived formal types and known discriminants
Date: Tue, 4 Jul 2017 09:09:53 +0200
Date: 2017-07-04T09:09:53+02:00 [thread overview]
Message-ID: <ojff01$12ul$1@gioia.aioe.org> (raw)
In-Reply-To: a1bd4695-00ff-49a8-a07a-84ebdb043202@googlegroups.com
On 04/07/2017 02:30, sbelmont700@gmail.com wrote:
> At the risk of having some of the other thread's shade thrown in
> here, aren't tagged discriminated records the de facto way of doing
> initialization? That is, extending a Controlled type and then using
> discriminants in place of ctor arguments?
Sure. I am using this quite frequently. Sometimes I go this way:
type Factory_Type is record ...;
type Actual_Type (Parameters : not null access Factory_Type) is
tagged ...;
There are obvious limitations to that. Especially that you have to keep
parameters after object construction. Of course one can also do this:
type Factory_Type is record ...;
type Factory_Type_Ptr is access Factory_Type'Class;
type Actual_Type (Parameters : Factory_Type_Ptr) is
new Limited_Controlled ...;
Then in the Initialize you call Unchecked_Deallocate on Parameters and
comment with an appropriate number of exclamation marks that objects
must be created this way:
X : Actual_Type (new Parameter'(...));
Isn't getting rid of such constructs a valid argument to have proper
constructors?
BTW, if discriminants were abstracted as they should have been, that
would be the way to implement constructors with parameters. You could
declare a parameter as a public discriminant non-existing in the actual
implementation and the type user would have to supply it when declaring
an object.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2017-07-04 7:09 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-23 0:45 derived formal types and known discriminants sbelmont700
2017-06-23 17:26 ` Randy Brukardt
2017-06-29 14:15 ` sbelmont700
2017-06-29 14:39 ` Dmitry A. Kazakov
2017-06-29 17:40 ` Robert Eachus
2017-06-30 1:10 ` Randy Brukardt
2017-06-30 7:24 ` Dmitry A. Kazakov
2017-06-30 18:09 ` Randy Brukardt
2017-07-04 0:30 ` sbelmont700
2017-07-04 1:36 ` gautier_niouzes
2017-07-04 2:29 ` Randy Brukardt
2017-07-04 7:09 ` Dmitry A. Kazakov [this message]
2017-07-04 17:34 ` Shark8
2017-07-03 17:24 ` Jere
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox