comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Rationale for this not to compile?
Date: Fri, 25 Jul 2014 14:45:49 -0500
Date: 2014-07-25T14:45:49-05:00	[thread overview]
Message-ID: <lquc5d$3t0$1@loke.gir.dk> (raw)
In-Reply-To: wccvbql5won.fsf@shell01.TheWorld.com

"Robert A Duff" <bobduff@shell01.TheWorld.com> wrote in message 
news:wccvbql5won.fsf@shell01.TheWorld.com...
> "Randy Brukardt" <randy@rrsoftware.com> writes:
>
>> One of my pet projects (that I don't have any time to follow up on!) is 
>> to
>> create a useful container where the element type is a formal incomplete
>> type. I think that the container would have to manage elements that live
>> elsewhere (unlike Ada.Containers) -- since element creation isn't 
>> possible,
>> but this would allow a container of limited elements, and of course would
>> allow instantiation by a private type as here.
>
> Sounds interesting, but I don't understand what you mean by "live
> elsewhere".  Could you outline how this would work?  I'm having trouble
> seeing what use is a "container" that doesn't contain any elements.

I left out one part: the elements would have to be tagged, because "tagged 
incomplete" allows a number of things that regular incomplete doesn't. (In 
particular, they're assumed to be passed by-reference, so parameters are 
allowed). Access after insertion would be via Reference/Constant_Reference 
only (can't make a copy of the element, obviously, and no functions can 
return the element).

Anyway, you can't create an object of an incomplete type, so the client has 
to do that before adding it to the container. That means the container's job 
is to manage the relationships between the elements (and the lookup 
mechanism, for maps and sets).

For instance, one could have a bunch of tasks, and put them into a map 
container in order to add a lookup mechanism to them. Something like:

     Tasks : array (1 .. 10) of My_Task; -- Assume My_Task is tagged.
     package My_Task_Map is new Randys_Super_Duper_Map_Container (String, 
My_Task);
     My_Map : My_Task_Map.Map;
     ...
     My_Map.Insert ("Bob", Tasks(1));
     My_Map.Insert ("Randy", Tasks(2));
     My_Map.Insert ("Tucker", Tasks(3));
     My_Map.Insert ("Steve", Tasks(4));

    --
    My_Map("Bob").My_Entry (...); -- Entry call on the task associated with 
"Bob".

Does this make sense?

                                Randy.

 




  reply	other threads:[~2014-07-25 19:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-24 20:53 Rationale for this not to compile? Victor Porton
2014-07-24 21:36 ` Adam Beneschan
2014-07-25  5:29   ` Randy Brukardt
2014-07-25 12:19     ` Victor Porton
2014-07-25 12:35       ` AdaMagica
2014-07-25 14:40     ` Robert A Duff
2014-07-25 19:45       ` Randy Brukardt [this message]
2014-07-25 20:33         ` Robert A Duff
2014-07-25 13:18 ` Victor Porton
replies disabled

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