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,9d929352a358ccab X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!g44g2000cwa.googlegroups.com!not-for-mail From: "REH" Newsgroups: comp.lang.ada Subject: Re: Ada to C++ translator Date: 25 Jan 2006 15:19:14 -0800 Organization: http://groups.google.com Message-ID: <1138231154.271960.31270@g44g2000cwa.googlegroups.com> References: <1138132539.577082.206380@g43g2000cwa.googlegroups.com> <43D7FAA9.1617F97F@fakeaddress.nil> NNTP-Posting-Host: 192.35.35.34 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1138231159 5200 127.0.0.1 (25 Jan 2006 23:19:19 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 25 Jan 2006 23:19:19 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: g44g2000cwa.googlegroups.com; posting-host=192.35.35.34; posting-account=lnUIyw0AAACoRB2fMF2SFTIilm8F10q2 Xref: g2news1.google.com comp.lang.ada:2638 Date: 2006-01-25T15:19:14-08:00 List-Id: Gautier Write-only wrote: > Also, one point where a translation could look more like a > compilation is Ada's possibility of nesting subprograms or > packages into other subprograms or packages. > E.g. what is the C++ equivalent of the following (silly, > but correct) code ? > > with Ada.Text_IO; > > procedure Nest_Test is > > procedure P1(s1: String) is > > procedure P2(s2: String) is > begin > if s2'Length > 0 then > declare > generic > content: String; > package K1 is > procedure Spit; > end K1; > package body K1 is > procedure Spit is > begin > Ada.Text_IO.Put(content(content'First)); > P1(content(content'First+1..content'Last)); > end Spit; > end K1; > package my_K1 is new K1( content=> s2 ); > begin > my_K1.Spit; > end; > end if; > end P2; > > begin > P2(s1); > end P1; > > begin > P1("A very silly way to display a string!"); > end Nest_Test; These are great features of Ada, ones that I wish C++ had. The closed I could come to the above is: #include #include void Nest_Test() { struct P1 { P1(const std::string& s1) { struct P2 { P2(const std::string& s2) { struct Spit { Spit(const std::string& s2) { std::cout << s2[0]; P1(s2.substr(1)); } }; if (!s2.empty()) { Spit s(s2); } } }; P2 p(s1); } }; P1 p("A very silly way to display a string!"); } But it definitely is not as nice. And there is no way to define local templates, nor instantiate them with dynamic data.