comp.lang.ada
 help / color / mirror / Atom feed
From: Victor Porton <porton@narod.ru>
Subject: Some problems with iterators
Date: Wed, 20 Aug 2014 19:48:53 +0300
Date: 2014-08-20T19:48:53+03:00	[thread overview]
Message-ID: <lt2jhi$qpv$1@speranza.aioe.org> (raw)

Why Ada2012 does allow only type name for an iterator in for loops, not an 
iterator object?

I think, it is a design mistake. We should also accept iterator object, 
probably constructed earlier.

Now, it is probably possible to do this by introducing a dummy container 
(used only to initialize my iterator), but this is a hack. We should allow 
creation of iterators without unnecessary containers.

The following does not verify with GCC 4.9.1 (I think it is a compiler bug 
and have reported this bug in GCC Bugzilla):

with Ada.Iterator_Interfaces;

package Test is
   
   type Description_Cursor is new Natural;

   function Has_Element (Position: Description_Cursor) return Boolean;

   package Description_Iterators  is new 
Ada.Iterator_Interfaces(Description_Cursor, Has_Element);

   type Description_Iterator is new Description_Iterators.Forward_Iterator 
with null record;

   overriding function First (Object: Description_Iterator) return 
Description_Cursor;
   overriding function Next (Object: Description_Iterator; Position: 
Description_Cursor) return Description_Cursor;

   type Descriptions_List is tagged limited null record
     with Default_Iterator=>Get_Descriptions_Iterator;

   not overriding function Get_Descriptions_Iterator (List: 
Descriptions_List'Class) return Description_Iterator;

end Test;

However, if I remove 'Class in the declaration of Get_Descriptions_Iterator 
function, it does not work either:

test.ads:19:28: operation can be dispatching in only one type

This may indicate one more design error: I cannot define Default_Iterator of 
a suitable subprogram signature. Or is there any way to work around this 
problem? How to define it? Please show example code.

-- 
Victor Porton - http://portonvictor.org

             reply	other threads:[~2014-08-20 16:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-20 16:48 Victor Porton [this message]
2014-08-21  7:06 ` Some problems with iterators Egil H H
2014-08-21 16:34   ` Victor Porton
2014-08-21 16:46     ` Victor Porton
2014-08-21 23:01       ` Randy Brukardt
2014-08-22  7:59         ` Egil H H
replies disabled

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