"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