comp.lang.ada
 help / color / mirror / Atom feed
From: "Matthew Heaney" <mheaney@on2.com>
Subject: Re: prohibit certain generic instantiations in Ada 2005
Date: 13 Feb 2006 11:14:50 -0800
Date: 2006-02-13T11:14:50-08:00	[thread overview]
Message-ID: <1139858090.274110.26950@g44g2000cwa.googlegroups.com> (raw)
In-Reply-To: 1139734552.205623.152990@o13g2000cwo.googlegroups.com

Ada does have something called "signature packages" that are probably
what you're looking for.

The problem with your previous solutions is that you're trying to use
types to solve your problem, instead of using generics to solve your
problem (which was your original request).

You want to be doing something like:

generic
  type Engine is limited private;
  type Transmission is limited private;
  with procedure Attach (E : in out Engine; T : in out Transmission) is
<>;
  with <other ops req'd by body go here>
package Generic_Cars is ... end;

Don't import generic formal tagged types if you don't need them.  You
only end up overcommitting yourself.  Note that a limited private
generic formal is a superset of tagged (limited), so you're still free
to instantiate Generic_Cars with a tagged generic actual.

You want to prevent attaching an electric engine to a manual
transmission.  That's fine.  If no Attach for binding an electric
engine to a manual transmission exists, then your problem is solved
since you have no generic actual with which to instantiate the package.

Stop trying to import tagged types.  The only reason you'd need to do
that is if the generic package itself needs to extend the formal type.


Now that that's out of the way, I can get to what I mentioned at the
top of my post.  It's possible that the set of operations for engines
and transmissions needed by the generic is large, and so the generic
formal region becomes long since you must declare all the formal
operations.  To simplify things you can declare all the engine
operations in a separate package (and do the same for the transmission
in another package, if necessary), and then import an instantiation of
the engine "signature" package as a generic formal, like this:

generic
  type Engine (<>) is limited private;
  with procedure XXX (E : in out Engine) is <>;
  <lots of other engine ops here>
package Generic_Engines is end;  -- yes, spec is empty

Now you can do this:

generic
  type Engine is limited private;
  type Transmission is limited private;
  with Engines is new Generic_Engines (Engine, others => <>);  --
verify my syntax
  with procedure Attach (E : in out Engine; ...) is <>;
package Generic_Cars is ... end;

That way you can instantiate the Generic_Engines package once for each
interesting engine type (note again that you do NOT need a tagged type
here), and then use that signature package as the generic actual.

Stop using tagged types for everything.  You want signature packages.




      parent reply	other threads:[~2006-02-13 19:14 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
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 [this message]
replies disabled

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