"Randy Brukardt" <randy@[EMAIL PROTECTED]
> writes:
> Of course, you often do need assignment. The containers are non-limited
so
> that they can be composed. And that's because it doesn't make sense to
have
> limited elements (as the elements have to be copied into the container).
On that subject, we recently had need of a bounded list (for restricted
runtimes, sans dynamic memory allocation), something like:
generic
type ET is private;
with "=" (L, R : ET) return Boolean is <>;
package Ada.Containers.Bounded_Lists is
type List (Capacity : Count_Type) is tagged limited private;
... -- more or less same as Doubly_Linked_Lists
end;
That brings up the composability issue, since you'd like to be able to
create a
container whose elements are bounded lists. I came up with something
like:
generic
type ET is limited private;
package Ada.Containers.Limited_Bounded_Lists is
type List (Capacity : Count_Type) is tagged limited private;
function Element
(Container : not null access List;
Position : Cursor)
return not null access ET;
function Constant_Element
(Container : not null access constant List;
Position : Cursor)
return not null access constant ET;
function First_Element
(Container : not null access List)
return not null access ET;
function Constant_First_Element
(Container : not null access constant List)
return not null access constant ET;
....
end;
Query_Element and Update_Element are still there, but it's awfully nice to
be
able to rename an element directly. You can do something like:
procedure Op (L : in out List) is
begin
L.Append (Initialize'Access); -- init elem
-- or: L.Append; -- no init necessary
-- or: L.Insert (Before => No_Element, Process => Initialize'Access);
-- or: L.Insert (Before => No_Element);
declare
E : ET renames L.Last_Element; -- implicit 'Access
begin
... -- use E
end;
end Op;
The only potential issue is that if you rename an active element, it can
subsequently become inactive (if you Delete it) in the scope of the
renaming.
If you were to subsequently manipulate it that would probably be bad, but
at
least the object doesn't disappear as it would in the unbounded case,
since the
object just moves onto an internal free list owned by the list.
Don't know if that's the right thing to do, though. I haven't done
anything
with it yet so maybe I'll just get rid of those ops. It's just that in
the
case of a limited element, it's OK to declare the element as aliased,
since
there's no issue (I think) about constraining an element object whose type
is a
discriminated record with default discriminant.
It was nice to be able to bounce ideas off of the ARG subcommittee. We
ought
to set up a mailing list or something to discuss post-Ada 2005 container
issues. We might be able to reuse the old mailing list at yahoo if it's
still
around.
-Matt


|