CVS difference for ai05s/ai05-0139-2.txt

Differences between 1.15 and version 1.16
Log of other versions for file ai05s/ai05-0139-2.txt

--- ai05s/ai05-0139-2.txt	2011/04/19 06:04:29	1.15
+++ ai05s/ai05-0139-2.txt	2011/04/26 22:43:26	1.16
@@ -1,4 +1,4 @@
-!standard 4.1(2/2)                                    11-04-19  AI05-0139-2/11
+!standard 4.1(2/2)                                    11-04-26  AI05-0139-2/12
 !standard 4.1.5(0)
 !standard 4.1.6(0)
 !standard 5.5(3)
@@ -224,14 +224,14 @@
 What the above presumes is that the function Iterate returns an object
 of a type derived from a "magic" iterator type (see below). The
 iterator type provides a First and Next operation which return a Cursor
-type, and a No_Element cursor value to indicate end of iteration. The above
-expands into:
+type, and a Has_Element function that allows testing for the end of
+iteration. The above expands into:
 
    declare
       _Iter : Iterator_Type := Iterate(Container);
       Cursor : Cursor_Type := First(_Iter);
    begin
-      while Cursor /= No_Element loop
+      while Has_Element(Cursor) loop
          Container(Cursor) := Container(Cursor) + 1;
            -- This presumes an appropriate _Indexing aspect
            -- is defined.
@@ -244,8 +244,8 @@
 used to "enable" the above iterator syntax for a given cursor type:
 
    generic
-       type Cursor is private;
-       No_Element : in Cursor;
+       type Cursor; -- Formal incomplete type (see AI05-0213-1).
+       with function Has_Element (Position : Cursor) return Boolean;
    package Ada.Iterator_Interfaces is
 
        type Forward_Iterator is limited interface;
@@ -278,19 +278,20 @@
 REVERSE reserved word.
 
 The function First is expected to deliver the first cursor value for the
-iterator iterating in the forward direction, or return No_Element if no
-cursor value is available. The function Next is expected to deliver the
-next cursor value for the iterator iterating in the forward direction
-given the previous cursor value returned from a call to First or Next,
-or return No_Element if no additional cursor values are available.
+iterator iterating in the forward direction, or return a value for which
+Has_Element will return False if no cursor value is available. The
+function Next is expected to deliver the next cursor value for the iterator
+iterating in the forward direction given the previous cursor value returned
+from a call to First or Next, or return a value for which
+Has_Element will return False if no additional cursor values are available.
 
 The function Last is expected to deliver the last cursor value for the
-iterator iterating in the reverse direction, or return No_Element if no
-cursor value is available. The function Previous is expected to deliver
-the next cursor value for the iterator iterating in the reverse
-direction given the previous cursor value returned from a call to Last
-or Previous, or return No_Element if no additional cursor values are
-available.
+iterator iterating in the reverse direction, or return a value for which
+Has_Element will return False if no cursor value is available. The function
+Previous is expected to deliver the next cursor value for the iterator
+iterating in the reverse direction given the previous cursor value returned
+from a call to Last or Previous, or return a value for which
+Has_Element will return False if no additional cursor values are available.
 
 b) The second syntax is intended for iterating directly over the elements
 of a container or an array:
@@ -318,7 +319,7 @@
       _Iter : Iterator_Type := Container_Type'Default_Iterator(Container);
       _Cursor : Cursor := First(_Iter);
    begin
-      while _Cursor /= No_Element loop
+      while Has_Element(_Cursor) loop
         declare
           Elem : Container_Type'Iterator_Element renames Container(_Cursor);
             -- This requires an appropriate _Indexing aspect being defined
@@ -334,7 +335,8 @@
 Here is how this generic and the iterator-related aspects might be used:
 
     type Cursor_Type is ...
-    package Iterators is new Ada.Iterator_Interfaces(Cursor_Type, No_Element);
+    function Has_Element (Position : Cursor_Type) return Boolean;
+    package Iterators is new Ada.Iterator_Interfaces(Cursor_Type, Has_Element);
     type Container is ...
        with
          Variable_Indexing => Element,
@@ -602,8 +604,8 @@
   The following language-defined generic library package exists:
 
    generic
-       type Cursor is private;
-       No_Element : in Cursor;
+       type Cursor;
+       with function Has_Element (Position : Cursor) return Boolean;
    package Ada.Iterator_Interfaces is
 
        type Forward_Iterator is limited interface;
@@ -758,16 +760,16 @@
    /iterator_/name is evaluated and the denoted iterator object becomes
    the /loop iterator/. In a forward generalized iterator, the operation
    First of the iterator type is called on the loop iterator, to produce
-   the initial value for the loop parameter. If the initial value is
-   equal to No_Element, then the execution of the loop_statement is
-   complete. Otherwise, the sequence_of_statements is executed and then
-   the Next operation of the iterator type is called with the loop
+   the initial value for the loop parameter. If the result of calling
+   Has_Element on the initial value is False, then the execution of the
+   loop_statement is complete. Otherwise, the sequence_of_statements is
+   executed and then the Next operation of the iterator type is called with the loop
    iterator and the current value of the loop parameter to produce the
    next value to be assigned to the loop parameter. This repeats until
-   the loop parameter is equal to No_Element, or the loop is left as a
-   consequence of a transfer of control. For a reverse generalized
-   iterator, the operations Last and Previous are called rather than
-   First and Next.
+   the result of calling Has_Element on the loop parameter is False,
+   or the loop is left as a consequence of a transfer of control. For a
+   reverse generalized iterator, the operations Last and Previous are
+   called rather than First and Next.
 
    For an array component iterator, the /array_/name is evaluated and
    the array object denoted by the name becomes the /array for the
@@ -797,17 +799,17 @@
 
    For a forward container element iterator, the operation First of the
    iterator type is called on the loop iterator, to produce the initial
-   value for the loop cursor. If the initial value is equal to
-   No_Element, then the execution of the loop_statement is complete.
-   Otherwise, the sequence_of_statements is executed with the loop
+   value for the loop cursor. If the result of calling Has_Element on
+   the initial value is False, then the execution of the loop_statement
+   is complete. Otherwise, the sequence_of_statements is executed with the loop
    parameter denoting an indexing (see 4.1.6) into the iterable object
    for the loop, with the only parameter to the indexing being the
    current value of the loop cursor; then the Next operation of the
    iterator type is called with the loop iterator and the loop cursor to
    produce the next value to be assigned to the loop cursor.  This
-   repeats until the loop cursor is equal to No_Element, or until the
-   loop is left as a consequence of a transfer of control.  For a
-   reverse container element iterator, the operations Last and Previous
+   repeats until the result of calling Has_Element on the loop cursor is
+   False, or until the loop is left as a consequence of a transfer of control.
+   For a reverse container element iterator, the operations Last and Previous
    are called rather than First and Next. If the loop parameter is a
    constant (see above), then the indexing uses the default constant
    indexing function for the type of the iterable object for the loop;

Questions? Ask the ACAA Technical Agent