From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: Re: Equivalent of dynamic_cast (downcast) for tagged types
Date: Thu, 27 Jan 2011 18:50:22 +0100
Date: 2011-01-27T18:50:22+01:00 [thread overview]
Message-ID: <4d41b05e$0$6759$9b4e6d93@newsspool3.arcor-online.net> (raw)
In-Reply-To: <evoxe8yl0jfw.guw86vvdhuzb.dlg@40tude.net>
On 27.01.11 17:18, Dmitry A. Kazakov wrote:
> The above is a bad idea, because X might be a descendant of T which has
> overridden Do_Something. So you might be looking for this
>
> if X'Tag = T'Tag then -- X is of T
> Do_Something (T (X)); -- No dispatch
> end if;
>
The following seems to be working in Pure units, too,
since it does not depend on Ada.Tags:
procedure Foo (X : in out P.Some_Interface'Class) is
begin
declare
Dynamic_Cast_X : Descendant.T renames Descendant.T(X);
begin
Dynamic_Cast_X.Do_Something_For_Me;
end;
exception
when CE: Constraint_Error =>
-- X not of type Descendant.T ...
null;
end Foo;
next prev parent reply other threads:[~2011-01-27 17:50 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-27 15:46 Equivalent of dynamic_cast (downcast) for tagged types Maciej Sobczak
2011-01-27 16:18 ` Dmitry A. Kazakov
2011-01-27 17:10 ` J-P. Rosen
2011-01-27 17:35 ` Dmitry A. Kazakov
2011-01-27 22:49 ` Maciej Sobczak
2011-01-27 17:50 ` Georg Bauhaus [this message]
2011-01-27 22:35 ` Maciej Sobczak
2011-01-28 5:07 ` Yannick Duchêne (Hibou57)
2011-01-28 9:16 ` Dmitry A. Kazakov
2011-01-28 13:11 ` AdaMagica
2011-01-28 14:13 ` Dmitry A. Kazakov
2011-01-28 23:51 ` Randy Brukardt
2011-01-29 0:55 ` Adam Beneschan
2011-01-28 16:44 ` Adam Beneschan
2011-01-28 17:21 ` Dmitry A. Kazakov
2011-01-29 0:12 ` Randy Brukardt
2011-01-29 8:47 ` Dmitry A. Kazakov
2011-01-28 17:33 ` Adam Beneschan
2011-01-28 15:13 ` Maciej Sobczak
2011-01-28 17:47 ` Robert A Duff
2011-01-28 22:04 ` Maciej Sobczak
2011-01-30 20:22 ` Stephen Leake
2011-01-31 9:04 ` AdaCore, user community and communication channels Maciej Sobczak
2011-01-31 10:42 ` Georg Bauhaus
2011-01-27 19:33 ` Equivalent of dynamic_cast (downcast) for tagged types Adam Beneschan
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox