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.1 required=5.0 tests=BAYES_00,FREEMAIL_FROM, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,703c4f68db81387d X-Google-Thread: 109fba,703c4f68db81387d X-Google-Thread: 115aec,703c4f68db81387d X-Google-Thread: f43e6,703c4f68db81387d X-Google-Attributes: gid103376,gid109fba,gid115aec,gidf43e6,public X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news1.google.com!proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!news100.image.dk!news000.worldonline.dk.POSTED!not-for-mail From: "Peter Koch Larsen" Newsgroups: comp.lang.ada,comp.lang.c++,comp.realtime,comp.software-eng 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> Subject: Re: [OT] Re: Teaching new tricks to an old dog (C++ -->Ada) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original Message-ID: Date: Mon, 14 Mar 2005 16:42:00 +0100 NNTP-Posting-Host: 62.79.147.244 X-Complaints-To: news-abuse@wol.dk X-Trace: news000.worldonline.dk 1110814918 62.79.147.244 (Mon, 14 Mar 2005 16:41:58 MET) NNTP-Posting-Date: Mon, 14 Mar 2005 16:41:58 MET Organization: Customer of Tiscali A/S Xref: g2news1.google.com comp.lang.ada:9366 comp.lang.c++:45560 comp.realtime:1450 comp.software-eng:5016 Date: 2005-03-14T16:42:00+01:00 List-Id: "Dr. Adrian Wrigley" skrev i en meddelelse news:pan.2005.03.14.14.41.47.813082@linuxchip.demon.co.uk.uk.uk... > On Sat, 12 Mar 2005 09:42:26 +0100, Georg Bauhaus wrote: > >> Falk Tannh�user wrote: >>> Dr. Adrian Wrigley wrote: >>> >>>> But what of features not present in either? >>> >>> [...] >>> >>>> associative arrays (from Perl) >>> >>> Wouldn't that be std::map in C++? >> >> and in Ada 2005, >> >> Ada.Containers.Hashed_Maps and Ada.Containers.Hashed_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; > }; > > int main() > { > std::map hash; > compoundindex fred = { 1, 2, 4 }; > > hash[fred] = 0.123; First off, std::map is not hash-based. It is a sorted container. Now in order to use this, you need a comparing function. It can be the "standard" ordering function for your key or it can be a user specified function. > } > > cpptest.cpp: In function `int main()': > cpptest.cpp:14: error: `main()::compoundindex' uses local type > `main()::compoundindex' > (8 more lines of errors here!) You must have snipped the most interesting errormessage. > > (what is the simplest C++ code to get this intent?) What you need here is a comparator: bool operator<(compoundindex const& lhs,compoundindex const& rhs) { .... } And the map should work. > -- > 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... > > > 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. > > I don't think I am being *that* unreasonable in asking for arrays > indexed by arbitrary types, without jumping through hoops :) But I do! How can you index without at least knowing if two values are different or the same? The C++ standard will have a hash-based container later. Those interested in having one can download one from e.g. boost (I believe this container also to be implemented by boost and prbably several others). > -- > Adrian > /Peter