From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: Victor Porton Newsgroups: comp.lang.ada Subject: Some problems with iterators Date: Wed, 20 Aug 2014 19:48:53 +0300 Organization: Aioe.org NNTP Server Message-ID: NNTP-Posting-Host: AnnUDmZwVERVUXyHDyOl5A.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Complaints-To: abuse@aioe.org User-Agent: KNode/4.13.3 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:21856 Date: 2014-08-20T19:48:53+03:00 List-Id: 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