comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: prohibit certain generic instantiations in Ada 2005
Date: Fri, 10 Feb 2006 19:25:24 +0100
Date: 2006-02-10T19:25:15+01:00	[thread overview]
Message-ID: <idm74jcpsz3l.147l8qc55x0y6$.dlg@40tude.net> (raw)
In-Reply-To: 1139581110.636535.107910@g44g2000cwa.googlegroups.com

On 10 Feb 2006 06:18:30 -0800, matteo.bordin@gmail.com wrote:

> I understand and agree from a semantic point of view. However I would
> like to let the compiler perform some additional type checking on the
> generic instance. If the generic instantiation is not allowed, then I
> what the compiler to produce a compilation error. This makes sense if
> you are using generics as a generative tool for metaprogramming. This
> kind of things can be done in C++, which has a compilation model
> similar to Ada (for what concerns generics/templates).

I don't see how you came to this conclusion. C++ model is quite different,
especially with respect of your question - it isn't contract based. So,
basically, C++ is unable to check anything specific about the type of
template a parameter. Ada's model is contract based, so types are fully
checked. That in particular means, that there cannot be any "additional
type" checking. Probably you meant something else.

Note that the type contract can be strengthen in Ada by requiring some
additional subroutines. For example:

generic
   type S is new T with private;
   procedure Ad_Hoc (X : in out S) is <>;

Here we require a type from T'Class plus some procedure Ad_Hoc defined on
it.

However, it is a *bad* practice from software design perspective inherited
from Ada 83, which wasn't OO.

A proper way is to make T'Class + Ad_Hoc explicit. If, for whatever reason,
T is frozen, you should, as Matthew suggested, derive a new [maybe
abstract] base:

type T1 is abstract T with null record;
procedure Ad_Hoc (X : in out T1) is abstract;
   -- This is a proper contract now

generic
   type S is new T1 with private;
      -- Here we use the contract

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2006-02-10 18:25 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-09 18:01 prohibit certain generic instantiations in Ada 2005 matteo.bordin
2006-02-09 20:02 ` Matthew Heaney
2006-02-10 14:18   ` matteo.bordin
2006-02-10 18:25     ` Dmitry A. Kazakov [this message]
2006-02-10 19:03       ` Georg Bauhaus
2006-02-11 10:45         ` Dmitry A. Kazakov
2006-02-11  8:04       ` matteo.bordin
2006-02-11  9:54         ` Martin Krischik
2006-02-11 10:20           ` matteo.bordin
2006-02-11 12:46             ` Martin Krischik
2006-02-11 10:45         ` Dmitry A. Kazakov
2006-02-11 22:20           ` Jeffrey R. Carter
2006-02-11 15:36         ` Stephen Leake
2006-02-12  8:55           ` matteo.bordin
2006-02-12  9:49             ` Dmitry A. Kazakov
2006-02-12 12:41               ` matteo.bordin
2006-02-13 19:14             ` Matthew Heaney
replies disabled

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