comp.lang.ada
 help / color / mirror / Atom feed
From: Dmitry A. Kazakov <mailbox@dmitry-kazakov.de>
Subject: Re: How do I create an object instance from a tag?
Date: Thu, 20 Feb 2003 10:15:53 +0100
Date: 2003-02-20T10:15:53+01:00	[thread overview]
Message-ID: <tj595vgumbe066chne4ik19188t2k2sa3n@4ax.com> (raw)
In-Reply-To: v57jj28mmg2r08@corp.supernews.com

On Wed, 19 Feb 2003 12:36:25 -0600, "Randy Brukardt"
<randy@rrsoftware.com> wrote:

>"Grein, Christoph"<christoph.grein@eurocopter.com> wrote:
>>
>>So there are good reasons why there is not yet a solution for this
>problem.
>
>The main one is discriminants. Tagged type discriminants never have
>defaults. Moreover, you can add discriminants to any extension of a
>tagged type, so you never can know if you have any. And, certainly, the
>creation of an object with uninitialized discriminants is a no-no.

[ I think we have already discussed this. A full solution is IMO only
possible with proper constructors. ]

As for uninialized discriminants, compare:

type X (I : Positive) is record ...;

A : X;  -- Illegal
B : X := (I => 10, ...);  -- OK

How does it differ from:

A : X'Class (A_Tag);
   -- Raises an exception when A_Tag refers to an unconstrained type
A : X'Class (A_Tag) := Make_X;
   -- Dispatches to Make_X, which provides all constraints

The only diference is that the latter is not compile-time checkable. 

However this can be solved. For example, one could define two
different tag types: one for all types another for constrained types
only [with appropriate conversion functions between them]. Then with a
general tag, T'Class(Tag) would counted as unconstrained, and thus
illegal without an initialization. With a "constrained" tag
T'Class(Tag) would be OK.

>What you really want to do is force the calling of a particular
>constructor function. (That's what T'Class'Input does, after all, with
>T'Input being the constructor).
>
>If you have a dispatching constructor "Make", then you want something
>like:
>
>    Obj : T'Class := T.Make (<params>) using <tag object>;
>
>But the reviewers thought that special syntax was overkill for this
>problem, and no one has been able to come up with any other solution
>that really works.

Special syntax is bad here, because there is nothing special in
dispatching on the result. There is everything for that. IMO the
actual problem is an unability to specifiy the type of the target
object. Solve this, and the rest will come for free. IMHO tag should
be viewed as a constraint (discriminant) for T'Class.

---
Regards,
Dmitry Kazakov
www.dmitry-kazakov.de



  reply	other threads:[~2003-02-20  9:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-19  9:39 How do I create an object instance from a tag? Grein, Christoph
2003-02-19 13:26 ` Dmitry A. Kazakov
2003-02-19 18:36   ` Randy Brukardt
2003-02-20  9:15     ` Dmitry A. Kazakov [this message]
  -- strict thread matches above, loose matches on Subject: below --
2003-02-17 20:25 Steve
2003-02-18  8:29 ` Dmitry A. Kazakov
2003-02-18 18:14   ` Randy Brukardt
2003-02-19  2:27     ` Steve
2003-02-19  9:18       ` Dmitry A. Kazakov
2003-02-20 15:38 ` Julio Cano
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox