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: 103376,f428ff2031155951 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!i39g2000prd.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Equivalent of dynamic_cast (downcast) for tagged types Date: Thu, 27 Jan 2011 11:33:30 -0800 (PST) Organization: http://groups.google.com Message-ID: <998aeb0e-6a1d-46b6-9c3e-abb3c1ef255c@i39g2000prd.googlegroups.com> References: <375fb596-ab12-4cb0-a190-53d62b94b2e4@e9g2000vbi.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1296156811 4244 127.0.0.1 (27 Jan 2011 19:33:31 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 27 Jan 2011 19:33:31 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: i39g2000prd.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:17719 Date: 2011-01-27T11:33:30-08:00 List-Id: On Jan 27, 7:46=A0am, Maciej Sobczak wrote: > Hi, > > Unfortunately I need to HACK some equivalent of dynamic_cast in Ada. > > There is a limited tagged type T deriving from Limited_Controlled and > Some_Interface as well. > There is also a procedure like this: > > procedure Foo (X : in Some_Interface'Class); > > Inside Foo I would like to check if X is indeed T if X in T > and if so, I would > like to dynamic_cast to it and execute some operation on T. then Execute_Some_Operation_On (T(X)); end if; Wonderful, no? In Ada you get to write pretty much what you were thinking of doing. The C++ equivalent is quite elegant, if you consider the number of ugly punctuation characters and cryptically- named built-in identifiers to be a measure of elegance. -- Adam