Anyone know if GNAT plans to add procedure iterators?

I really like the concept of procedural iterators, they make iteration of custom containers much safer to implement, and it feels more intuitive for me. However, at least the latest version of GNAT doesn’t support them yet.

I was hoping maybe someone had heard if they were planned to be implemented?

If you are unfamiliar with it, it allows for implementing iteration without needing to use cursors, iterator_interfaces, access types (directly, implemented with procedure access types).

A short visual example:

   v : Vectors.Vector;
begin
   for (Item : Integer) of v.Iterate(<>) loop
      Put_Line(Item'Image);
   end loop;

Test implementation

   package Vectors is
      type Vector is tagged private;
      procedure Iterate
         (Self      : Vector; 
          Operation : not null access procedure(Value : Integer));
   private
      type Integer_Array is array(Integer range <>) of Integer;
      type Vector is tagged record
         Elements : Integer_Array(1..10) := 23;
      end record;
   end Vectors;

   package body Vectors is
      procedure Iterate
         (Self      : Vector; 
          Operation : not null access procedure(Value : Integer))
      is begin
         for Element of Self.Elements loop
            Operation(Element);
         end loop;
      end Iterate;
   end Vectors;

for a map it might look more like:

   m : Maps.Map;
begin
   for (Key, Value) of m.Iterate(<>) loop
      Put_Line(Key'Image & " => " & Value'Image);
   end loop;

Reference 1: Loop-body as anonymous procedure
Reference 2: Procedural Iterators

Making a program indistinguishable from a suburban train schedule? :wink: