comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Re: Sharing generic bodies across instantiations.
Date: Wed, 28 Jul 2010 06:10:00 -0700 (PDT)
Date: 2010-07-28T06:10:00-07:00	[thread overview]
Message-ID: <31fccf50-510e-4ca1-89b9-d267f3435ec5@d8g2000yqf.googlegroups.com> (raw)
In-Reply-To: 4c501408$0$2382$4d3efbfe@news.sover.net

On 28 Lip, 13:27, "Peter C. Chapin" <pcc482...@gmail.com> wrote:

> For example
>
> template< typename T >
> void f(const T &object)
> {
>   typename T::helper internal;
>   ...
>
> }
>
> 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



  reply	other threads:[~2010-07-28 13:10 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 [this message]
2010-07-28 16:32           ` Peter C. Chapin
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