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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e93f73587e2bc1c3 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!d8g2000yqf.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Sharing generic bodies across instantiations. Date: Wed, 28 Jul 2010 06:10:00 -0700 (PDT) Organization: http://groups.google.com Message-ID: <31fccf50-510e-4ca1-89b9-d267f3435ec5@d8g2000yqf.googlegroups.com> References: <4c4e2d69$0$2378$4d3efbfe@news.sover.net> <4c4f5c28$0$2375$4d3efbfe@news.sover.net> <7da1e21f-bec7-4607-923c-0fd6cbcfc753@t10g2000yqg.googlegroups.com> <4c501408$0$2382$4d3efbfe@news.sover.net> NNTP-Posting-Host: 137.138.182.236 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1280322600 5875 127.0.0.1 (28 Jul 2010 13:10:00 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 28 Jul 2010 13:10:00 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d8g2000yqf.googlegroups.com; posting-host=137.138.182.236; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6,gzip(gfe) Xref: g2news1.google.com comp.lang.ada:12630 Date: 2010-07-28T06:10:00-07:00 List-Id: On 28 Lip, 13:27, "Peter C. Chapin" wrote: > For example > > template< typename T > > void f(const T &object) > { > =A0 typename T::helper internal; > =A0 ... > > } > > Here T::helper might be a class or a typedef. Which makes no difference from the point of view of how to implement that. Think about: char buf[sizeof(T)]; This is essentially the only problem that you have to solve, and that does not seem to be very difficult. > Depending on what it is a > wide variety of uses are possible. No, all uses have to be compatible with the code of the template. Even though each T can have different ways of being used, the template has to target the common subset of all such possibilities - otherwise the program will not compile. In other words, it does not matter how wide is the variety introduced by different Ts - if the program compiles at all, it means that the template is compatible with the common subset of all Ts uses. This removes the variety out of the picture. > There could well be other corner cases > I'm not seeing right now... that is the 'nature' of C++ of which I spoke. Sorry, but you did not identify any corner case for the moment. > I realize that implementing the shared model in Ada would be hard as > well, but Ada constrains much more the way names in generic bodies can > be used. Not really. AARM explicitly refers to the code copying when defining the meaning of generics, see 12.3, especially this: "The instance is a copy of the text of the template." (12.3/13) and then a whole lot of consequent descriptions that are implied by this. I would even say that by being so explicit with this, AARM gives more reasons to do macro-expansion than C++. > > But, for the sake of exercise, think about a C++ *interpreter*. > > That seems like a different situation to me. A pure interpreter executes > code only as needed and only when needed. Without a compilation step > isn't the question of shared or replicated bodies meaningless? Bingo and that's my point. This is why it does not make any sense to say that C++ prevents some implementation scenario. I can even imagine a combined approach, where each instantiation has a facade that is distinct (this can target stuff like static objects) and an actual implementation that is shared. -- Maciej Sobczak * http://www.inspirel.com YAMI4 - Messaging Solution for Distributed Systems http://www.inspirel.com/yami4