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=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,f428ff2031155951 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder2.cambriumusenet.nl!feed.tweaknews.nl!193.141.40.65.MISMATCH!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Thu, 27 Jan 2011 18:50:22 +0100 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Equivalent of dynamic_cast (downcast) for tagged types References: <375fb596-ab12-4cb0-a190-53d62b94b2e4@e9g2000vbi.googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <4d41b05e$0$6759$9b4e6d93@newsspool3.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 27 Jan 2011 18:50:22 CET NNTP-Posting-Host: 178e742d.newsspool3.arcor-online.net X-Trace: DXC=Oc1N757j7WS<<0iRN7DLEQMcF=Q^Z^V3X4Fo<]lROoRQ8kFZLh>_cHTX3j]g[?_V=Pc`LZ X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:17716 Date: 2011-01-27T18:50:22+01:00 List-Id: 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;