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 X-Received: by 2002:a24:100a:: with SMTP id 10mr32358903ity.34.1546444082125; Wed, 02 Jan 2019 07:48:02 -0800 (PST) X-Received: by 2002:a9d:24c3:: with SMTP id z61mr911091ota.1.1546444081825; Wed, 02 Jan 2019 07:48:01 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!fdn.fr!proxad.net!feeder1-2.proxad.net!209.85.166.216.MISMATCH!q69no53544itb.0!news-out.google.com!v141ni107ita.0!nntp.google.com!q69no53539itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 2 Jan 2019 07:48:01 -0800 (PST) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=85.168.19.89; posting-account=O_NgcgoAAABs6pgCjroQBmOBL5ZZGPUc NNTP-Posting-Host: 85.168.19.89 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: class wide iterable (and indexable) From: George Shapovalov Injection-Date: Wed, 02 Jan 2019 15:48:02 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader01.eternal-september.org comp.lang.ada:55164 Date: 2019-01-02T07:48:01-08:00 List-Id: Hello, I apologize if something like this is a common thing, but search here or on= google does not turn up much of directly related info, and I cannot quite = understand why the following confuses gnat.. The intention here is to create a top-level interface providing iterable/in= dexable, well, interface, with specific derived types providing appropriate= data handling (say to let user select either dynamic, Ada.Containers.Vecto= rs based, or fixed, based on plain arrays storage).=20 See here for working code: https://github.com/gerr135/ada_gems/tree/master/list_iface So, I would have=20 package Lists is .. type List_Interface is interface with Constant_Indexing =3D> List_Constant_Reference, Variable_Indexing =3D> List_Reference, Default_Iterator =3D> Iterate, Iterator_Element =3D> Element_Type; package Lists.Dynamic is .. type List is new List_Interface with private .. package Lists.Fixed is .. type List is new List_Interface with private.. with all appropriate elements declared as abstract and derived types implem= enting them - either directly attaching Vector interface or wrapping around= base array.. Then common code could be kept in class-wide methods, using the new loop fo= rms, like in: -- for item of List loop do_something(item); end loop; as well as direct indexing, i.e. List(i) -- with specific storage types selected as needed in client procedures. In mos= t optimistic scenario only declarative region would need light changes.. This all works well in fact, as long as I operate on specific types. But as= soon as I try to use class-wide variable, the "of" form of the loop seems = to confuse the compiler. Thus, e.g.=20 LL : Lists.Dynamic.List; for l of LL loop .. -- works fine but LC : Lists.List_Interface'Class :=3D Lists.Dynamic.To_Vector(5); for l of LC loop .. -- confuses the compiler And I just cannot see what's so special about this class-wide here. It all = seems to follow exactly the same form (by design it passes all compiler che= cks up to this point). Please see here for the code: https://github.com/gerr135/ada_gems/tree/master/list_iface the specific error is: test_list_iface.adb:91:17: expected type "Standard.Integer" test_list_iface.adb:91:17: found private type "Cursor" defined at lists.ads= :32, instance at line 22 (and one more line further down that is clearly derivative) This is not quite a 5-line example code, but implementing iterable/indexabl= e interfaces with proper inheritance is somewhat beasty (even if its utilit= y is in concise end-point code). I am afraid this is the minimal code that = would illustrate the point (cut and reformed from larger project where I wa= s trying such approach. Perhaps I should turn to iterating over some index = type, which needs to be provided anyway. Seems to be simpler and as readabl= e, but what is there the new interface for, if not to be tried out? :) ). I would be thankful for any pointers, as I am at a loss what that class-wid= e for loop is getting confused about. Or why it even expects the Index type= in the "of" loop? Thank you for any pointers. George