Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ada > Re: limited typ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 9 of 26 Topic 4222 of 5930
Post > Topic >>

Re: limited types (Was: Records that could be arrays)

by Matthew Heaney <matthewjheaney@[EMAIL PROTECTED] > Feb 26, 2006 at 06:20 PM

"Dmitry A. Kazakov" <mailbox@[EMAIL PROTECTED]
> writes:

> On Sat, 25 Feb 2006 15:05:02 GMT, Matthew Heaney wrote:
> 
> > But you can pass in an Initialize procedure as a parameter of an
insertion
> > operation, to perform whatever initialization needs to be done.
> 
> You mean "return .. do" for limited types. 

For an unbounded form, you could do it either way, via an Initialize
procedure,
or via a Copy function (using the new return do syntax).

For a bounded form, only an Initialize procedure would work, since the
actual
initialization of the elements happens only once, when the (bounded)
container
object is elaborated.


> It is in-place, but a constructing function does not have safety of a
> constructor. 

Huh?  An Ada 2005 constructor function *is* a constructor.  It's no
different
from a copy ctor in C++.


> Then you cannot ask it from the type, so it can't have a default
> [deduced from the type.]. It is not dispatching in Insert. 

Aren't constructors always non-dispatching (unless you're using a Factory
Method pattern)?  But this is no different from the C++ STL.

If you have an container (of indefinite elements) instantiated with
(limited)
type T'Class, then I suppose you might want to have a dispatching
constructor.
I'd have to think about how to do that[but see below].  (In my earlier
example
I was really thinking of bounded forms, which cannot have indefinite
elements.)


> What about container of class-wides, i.e. when Node_Type should have
> ET'Class?

Only applies to unbounded containers whose elements are indefinite.  GCC
allocates each indefinite element (so Node_Type has a pointer to ET).  

In general there's never any direct dispatching inside a generic, since
the
generic formal region doesn't pass in any operations, the formal type
isn't
tagged, and formal operations must be statically bound to the element
type.

If you wanted a contructor to dispatch, you'd have to say (assuming my
knowledge of Ada 2005 is correct):

  type ET is tagged limited private;
  function Copy (E : ET) return ET;  -- primitive op

  function Copy_Classwide (E : ET'Class) return ET'Class is
  begin
    return Copy (E);  -- legal Ada 2005?
  end;
  
Then you pass this in as per the example of my earlier post:

  package List_Types is
    new Limited_Indefinite_Lists (ET'Class);
  ...

  procedure Op (L : in out List) is
  begin
    ...
    L.Insert (...New_Item => E, Copy => Copy_Classwide...);
    ...
  end;

Then the primitive Copy operation will dispatch according to the tag of
actual
parameter E.  This is always what you do inside a generic to enable
dispatching
(when the generic formal type is non-tagged and indefinite).


> ... and of course passing pointers to functions is ugly.

This is not an argument.  The existing API already has function pointers
everywhere, so you might as well get used to it.
 




 26 Posts in Topic:
limited types (Was: Records that could be arrays)
Thierry Bernier <email  2006-02-24 16:51:03 
Re: limited types (Was: Records that could be arrays)
"Randy Brukardt"  2006-02-24 15:57:46 
Re: limited types (Was: Records that could be arrays)
Matthew Heaney <matthe  2006-02-25 02:21:13 
Re: limited types (Was: Records that could be arrays)
Matthew Heaney <matthe  2006-02-25 03:38:59 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-25 12:06:20 
Re: limited types (Was: Records that could be arrays)
Matthew Heaney <matthe  2006-02-25 15:05:02 
Re: limited types (Was: Records that could be arrays)
"Randy Brukardt"  2006-02-25 19:01:06 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-26 10:00:07 
Re: limited types (Was: Records that could be arrays)
Matthew Heaney <matthe  2006-02-26 18:20:39 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-26 21:52:32 
Re: limited types (Was: Records that could be arrays)
Matthew Heaney <matthe  2006-02-26 22:07:00 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-27 10:11:28 
Re: limited types (Was: Records that could be arrays)
Georg Bauhaus <bauhaus  2006-02-27 15:34:58 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-27 17:05:47 
Re: limited types (Was: Records that could be arrays)
"Matthew Heaney"  2006-02-27 08:52:23 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-27 21:21:08 
Re: limited types (Was: Records that could be arrays)
Georg Bauhaus <bauhaus  2006-02-27 22:40:18 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-28 10:38:31 
Re: limited types (Was: Records that could be arrays)
"Matthew Heaney"  2006-02-27 15:00:29 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-28 10:39:20 
Re: limited types (Was: Records that could be arrays)
"Matthew Heaney"  2006-02-28 09:24:35 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-28 20:06:50 
Re: limited types (Was: Records that could be arrays)
"Matthew Heaney"  2006-02-28 11:58:11 
Re: limited types (Was: Records that could be arrays)
"Dmitry A. Kazakov&q  2006-02-28 22:03:37 
Re: limited types
Simon Wright <simon@[E  2006-02-28 21:51:52 
Re: limited types
Matthew Heaney <matthe  2006-03-01 01:59:16 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 13 9:11:28 CDT 2008.