comp.lang.ada
 help / color / mirror / Atom feed
From: "Peter C. Chapin" <pcc482719@gmail.com>
Subject: Re: Sharing generic bodies across instantiations.
Date: Wed, 28 Jul 2010 12:32:37 -0400
Date: 2010-07-28T12:32:37-04:00	[thread overview]
Message-ID: <4c505b89$0$2372$4d3efbfe@news.sover.net> (raw)
In-Reply-To: <31fccf50-510e-4ca1-89b9-d267f3435ec5@d8g2000yqf.googlegroups.com>

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



  reply	other threads:[~2010-07-28 16:32 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-27  0:51 Sharing generic bodies across instantiations Peter C. Chapin
2010-07-27  3:01 ` Gene
2010-07-27  6:55 ` AdaMagica
2010-07-27 11:29   ` Ludovic Brenta
2010-07-27 14:10     ` Tero Koskinen
2010-07-27 10:51 ` Martin
2010-07-27 20:06 ` anon
2010-07-27 22:23   ` Peter C. Chapin
2010-07-28  7:59     ` Maciej Sobczak
2010-07-28  9:28       ` Dmitry A. Kazakov
2010-07-28 12:55         ` Maciej Sobczak
2010-07-28 13:16           ` Dmitry A. Kazakov
2010-07-28 19:48             ` Maciej Sobczak
2010-07-29  8:03               ` Dmitry A. Kazakov
2010-07-29 14:02                 ` Maciej Sobczak
2010-07-29 14:40                   ` Dmitry A. Kazakov
2010-07-29 20:27                     ` Maciej Sobczak
2010-07-30  9:09                       ` Dmitry A. Kazakov
2010-07-30 12:31                         ` Maciej Sobczak
2010-07-30 14:59                           ` Dmitry A. Kazakov
2010-08-03  3:02                           ` Randy Brukardt
2010-08-03 14:37                             ` Robert A Duff
2010-08-03  2:47                         ` Randy Brukardt
2010-07-28 20:01             ` Keith Thompson
2010-07-29  7:46               ` Dmitry A. Kazakov
2010-07-28 11:27       ` Peter C. Chapin
2010-07-28 13:10         ` Maciej Sobczak
2010-07-28 16:32           ` Peter C. Chapin [this message]
2010-07-28 19:30             ` Robert A Duff
2010-07-28 20:03             ` Maciej Sobczak
2010-07-28 11:47     ` anon
2010-08-03  2:38     ` Randy Brukardt
2010-08-03 14:31       ` Robert A Duff
2010-07-28  0:55   ` Keith Thompson
2010-07-28  8:42     ` Markus Schoepflin
2010-07-28 11:16     ` anon
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox