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!news3.google.com!newsfeed2.dallas1.level3.net!news.level3.com!newsfeed-00.mathworks.com!kanaga.switch.ch!news-zh.switch.ch!switch.ch!cernne03.cern.ch!cern.ch!news From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Ada to C++ translator Date: Thu, 26 Jan 2006 10:17:12 +0100 Organization: CERN - European Laboratory for Particle Physics Message-ID: References: <1138132539.577082.206380@g43g2000cwa.googlegroups.com> <43D7FAA9.1617F97F@fakeaddress.nil> NNTP-Posting-Host: abpc10883.cern.ch Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sunnews.cern.ch 1138267032 16616 (None) 137.138.37.241 X-Complaints-To: news@sunnews.cern.ch User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050922 Red Hat/1.7.12-1.1.3.2.SL3 X-Accept-Language: en-us, en In-Reply-To: <43D7FAA9.1617F97F@fakeaddress.nil> Xref: g2news1.google.com comp.lang.ada:2643 Date: 2006-01-26T10:17:12+01:00 List-Id: Gautier Write-only wrote: > 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; #include #include #include namespace P1 { namespace P2 { template struct K1 { K1(Content const &c) : content(c) {} void Spit(); Content content; }; template void K1::Spit() { std::cout << content[0]; ::P1::execute(Content(content.begin() + 1, content.end())); } void execute(std::string const &s2) { if (s2.size() > 0) { K1 my_K1(s2); my_K1.Spit(); } } } void execute(std::string const &s1) { P2::execute(s1); } } int main() { P1::execute("Indeed a very silly way!"); std::cout << '\n'; } -- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/