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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,703c4f68db81387d X-Google-Thread: 109fba,703c4f68db81387d X-Google-Attributes: gid103376,gid109fba,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!stamper.news.atl.earthlink.net!newsread2.news.atl.earthlink.net.POSTED!14bb18d8!not-for-mail Sender: mheaney@MHEANEYX200 Newsgroups: comp.lang.ada,comp.lang.c++ Subject: Re: [OT] Re: Teaching new tricks to an old dog (C++ -->Ada) References: <4229bad9$0$1019$afc38c87@news.optusnet.com.au> <1110032222.447846.167060@g14g2000cwa.googlegroups.com> <871xau9nlh.fsf@insalien.org> <3SjWd.103128$Vf.3969241@news000.worldonline.dk> <87r7iu85lf.fsf@insalien.org> <1110052142.832650@athnrd02> <42309456$1@news.broadpark.no> <4232ab3a$0$26547$9b4e6d93@newsread4.arcor-online.net> From: Matthew Heaney Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Wed, 23 Mar 2005 13:49:25 GMT NNTP-Posting-Host: 24.149.57.125 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.news.atl.earthlink.net 1111585765 24.149.57.125 (Wed, 23 Mar 2005 05:49:25 PST) NNTP-Posting-Date: Wed, 23 Mar 2005 05:49:25 PST Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: g2news1.google.com comp.lang.ada:9797 comp.lang.c++:46809 Date: 2005-03-23T13:49:25+00:00 List-Id: "Dr. Adrian Wrigley" writes: > >> Wouldn't that be std::map in C++? > > > > and in Ada 2005, > > > > Ada.Containers.Hashed_Maps and Ada.Containers.Hashed_Maps Ada 2005 will have both ordered ("sorted") maps and hashed maps. The current C++ standard only has ordered maps. > I have probably missed a trick in the C++, but I couldn't get > std::map code to compile (except in the trivial cases): > > #include > > struct compoundindex { > int a, b, c; > }; This type doesn't have a relational operator, which you need to instantiate the map. > -- > The Ada associative arrays from the new draft standard > are specified as something like: > > generic > type Key_Type is private; > type Element_Type is private; > with function Hash (Key : Key_Type) > return Hash_Type is <>; > with function Is_Equal_Key (Left, Right : Key_Type) > return Boolean is "="; > with function "=" (Left, Right : Element_Type) > return Boolean is <>; > package Ada.Containers.Hashed_Maps is... Yes, but the analog to the C++ map is Ada.Containers.Ordered_Maps, not the hashed map. > Which clearly won't work unless you can find the three > function generic parameters. I don't see how this can be > used easily in a generic context. But this is true of C++ as well. There's no magic: your key either needs a relational operator (for the ordered map), or it needs a hash function (for the hashed map). > I don't think I am being *that* unreasonable in asking for arrays > indexed by arbitrary types, without jumping through hoops :) Requiring that the key used to instantiate a hashed map have a hash function hardly constitutes "jumping through hoops." In any event, you probably want an ordered map anyway: generic type Key_Type is private; type Element_Type is private; with function "<" (Left, Right : Key_Type) return Boolean is <>; with function "=" (Left, Right : Element_Type) return Boolean is <>; package Ada.Containers.Ordered_Maps is in which case all you need is a relational op: function "<" (L, R : Compound_Index) return Boolean is begin if L.A < R.A then return True; end if; if L.A > R.A then return False; end if; if L.B < R.B then ... end; package Compound_Index_Maps is new Ada.Containers.Ordered_Maps (Compound_Index, Float); declare M : Compound_Index_Maps.Map; begin M.Include (Key => (1, 2, 4), New_Item => 0.123); end;