comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthewjheaney@earthlink.net>
Subject: Re: limited types (Was: Records that could be arrays)
Date: Sat, 25 Feb 2006 02:21:13 GMT
Date: 2006-02-25T02:21:13+00:00	[thread overview]
Message-ID: <upslctbzc.fsf@earthlink.net> (raw)
In-Reply-To: BfCdnQZCaeilHWLenZ2dnUVZ_vmdnZ2d@megapath.net

"Randy Brukardt" <randy@rrsoftware.com> 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



  reply	other threads:[~2006-02-25  2:21 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-24 16:51 limited types (Was: Records that could be arrays) Thierry Bernier
2006-02-24 21:57 ` Randy Brukardt
2006-02-25  2:21   ` Matthew Heaney [this message]
2006-02-25  3:38     ` Matthew Heaney
2006-02-25 11:06   ` Dmitry A. Kazakov
2006-02-25 15:05     ` Matthew Heaney
2006-02-26  1:01       ` Randy Brukardt
2006-02-26  9:00       ` Dmitry A. Kazakov
2006-02-26 18:20         ` Matthew Heaney
2006-02-26 20:52           ` Dmitry A. Kazakov
2006-02-26 22:07             ` Matthew Heaney
2006-02-27  9:11               ` Dmitry A. Kazakov
2006-02-27 14:34                 ` Georg Bauhaus
2006-02-27 16:05                   ` Dmitry A. Kazakov
2006-02-27 16:52                     ` Matthew Heaney
2006-02-27 20:21                       ` Dmitry A. Kazakov
2006-02-27 21:40                         ` Georg Bauhaus
2006-02-28  9:38                           ` Dmitry A. Kazakov
2006-02-27 23:00                         ` Matthew Heaney
2006-02-28  9:39                           ` Dmitry A. Kazakov
2006-02-28 17:24                             ` Matthew Heaney
2006-02-28 19:06                               ` Dmitry A. Kazakov
2006-02-28 19:58                                 ` Matthew Heaney
2006-02-28 21:03                                   ` Dmitry A. Kazakov
2006-02-28 21:51                                   ` limited types Simon Wright
2006-03-01  1:59                                     ` 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