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-7-bit Path: g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!novia!transit4.readnews.com!textspool1.readnews.com!news-out.readnews.com!postnews3.readnews.com!not-for-mail Date: Wed, 28 Jul 2010 12:32:37 -0400 From: "Peter C. Chapin" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.7) Gecko/20100713 Lightning/1.0b2 Thunderbird/3.1.1 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Sharing generic bodies across instantiations. 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> <31fccf50-510e-4ca1-89b9-d267f3435ec5@d8g2000yqf.googlegroups.com> In-Reply-To: <31fccf50-510e-4ca1-89b9-d267f3435ec5@d8g2000yqf.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <4c505b89$0$2372$4d3efbfe@news.sover.net> Organization: SoVerNet (sover.net) NNTP-Posting-Host: 364da55b.news.sover.net X-Trace: DXC=mkAE2CIc>1[:1[;=564oO_K6_LM2JZB_S2h<^iA^CNJQ:WUUlR<856_8_;E4MM4hOU\05GMT0?<^[ X-Complaints-To: abuse@sover.net Xref: g2news1.google.com comp.lang.ada:12636 Date: 2010-07-28T12:32:37-04:00 List-Id: On 2010-07-28 09:10, Maciej Sobczak wrote: >> 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. Well there could be more to it than that. If T is a class with methods (that are used in the template body) then the shared implementation approach would have to contend with that. If the template body tries to derive a class from T, perhaps overriding some of T's virtual functions there is that to think about as well. Perhaps the template body will throw a T object as an exception... although that might not be any more complicated than tracking T's copy constructor and destructor. In any case it seems like the compiler, in the shared implementation approach, would have to pass in a hidden object into the template code that details the capabilities of T that could be used by the shared generic code (pointers to appropriate functions, etc). I can see that only the capabilities actually used by the template would need to be described but there would certainly be more than just the size of a T involved. I assume this is how it would work in Ada as well. The difference is (might be) that in Ada there are more limitations on what a generic can do so the list of things to worry about would be shorter. As I said I haven't implemented either an Ada compiler nor a C++ compiler so I'm not sure exactly what the problems might be. That is what I was asking. :) > 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) That's interesting. Thanks for pointing that out. I wonder if that's intended to be taken literally or if that really means the instance must behave "as if" it is a copy of the text of the template. > Bingo and that's my point. This is why it does not make any sense to > say that C++ prevents some implementation scenario. Well, okay. I see what you mean. To say the standard forbids a certain implementation strategy is perhaps going too far. But there is a sense of what can reasonably be done. The C++ community doesn't talk much about a shared implementation of templates. Is that because it's just unreasonably difficult in C++? I think many people in that community would regard a pure interpreter as having too big a performance hit to be acceptable. Of course I can't speak for everyone. Peter