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, T_FILL_THIS_FORM_SHORT autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,443dd11dd1cfaec9,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.220.230 with SMTP id pz6mr1587616pbc.3.1344320952399; Mon, 06 Aug 2012 23:29:12 -0700 (PDT) Path: p10ni2516515pbh.1!nntp.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!ctu-peer!news.nctu.edu.tw!goblin1!goblin.stu.neva.ru!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: ms Newsgroups: comp.lang.ada Subject: Abstraction over container iterators Date: Fri, 3 Aug 2012 05:01:41 -0700 (PDT) Organization: http://groups.google.com Message-ID: <75425fa8-7885-48d8-9eeb-8f90a1bfb128@googlegroups.com> NNTP-Posting-Host: 83.144.73.246 Mime-Version: 1.0 X-Trace: posting.google.com 1343995302 16731 127.0.0.1 (3 Aug 2012 12:01:42 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 3 Aug 2012 12:01:42 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=83.144.73.246; posting-account=Qm6IFAoAAADLRMuMbYtLLXPPuIEGRdpu User-Agent: G2/1.0 X-Received-Bytes: 4596 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-08-03T05:01:41-07:00 List-Id: I'll let the code speak first: ----------------------------------------------- with Ada.Containers.Hashed_Maps; = =20 with Ada.Strings.Unbounded; = =20 with Ada.Strings.Unbounded.Hash_Case_Insensitive; = =20 with Ada.Strings.Unbounded.Equal_Case_Insensitive; = =20 package Environments is = =20 type Environment is tagged private; = =20 function Variable ( = =20 E : in Environment; = =20 Name : in Ada.Strings.Unbounded.Unbounded_String = =20 ) = =20 return Ada.Strings.Unbounded.Unbounded_String = =20 with Inline; = =20 procedure Set_Variable ( = =20 E : in out Environment; = =20 Name : in Ada.Strings.Unbounded.Unbounded_String; = =20 Value : in Ada.Strings.Unbounded.Unbounded_String = =20 ) = =20 with Inline; = =20 private = =20 package Variable_Maps is new Ada.Containers.Hashed_Maps ( = =20 Key_Type =3D> Ada.Strings.Unbounded.Unbounded_String, = =20 Element_Type =3D> Ada.Strings.Unbounded.Unbounded_String, = =20 Hash =3D> Ada.Strings.Unbounded.Hash_Case_Insensitive, = =20 Equivalent_Keys =3D> Ada.Strings.Unbounded.Equal_Case_Insensitive, = =20 "=3D" =3D> Ada.Strings.Unbounded."=3D" = =20 ); = =20 type Environment is tagged record = =20 Variables : Variable_Maps.Map; = =20 end record; = =20 end Environments; ----------------------------------------------- What we have here is an example package fairly well illustrating my problem= . I'm storing some environment variables in Hashed_Map, but I want to build= a abstraction layer over the standard container, so I can in future change= the underlaying container without changing any code in my package's custom= ers. Getting and setting variables is easy - as declared above. The real problem= is iterating. I'd like to let my package's customers to iterate over the e= nvironment and get both key and value for each element easily. As I'm using Ada 2012 the best way would be to use iterators, but how? I co= uld return a cursor to the underlaying container, but again, this cursor's = interface would be container-dependent. What would you say is the best way to achieve such abstraction over standar= d container iteration?