Re: [OT] Re: Teaching new tricks to an old dog (C++ -->Ada)
From: Dr. Adrian Wrigley (amtw_at_linuxchip.demon.co.uk.uk.uk)
Date: Mon, 14 Mar 2005 17:16:44 GMT
On Mon, 14 Mar 2005 17:06:10 +0100, Falk Tannhäuser wrote:
> Alternatively, if there is no natural definition for a general-purpose
> operator< for the key type in question, it is possible to create a
> comparison functor and to instantiate the container with it as
> supplementary template parameter.
the problem as I suggested in my previous post is that you have to
pass in the comparison operator or hash function down the tree
of template/generic instantiation, (composing them along the way)
if you want to use maps/hashes. If the necessary functions are
not passed in and built up, you can't instantiate the map/hash.
This means that you can't write an implementation of a template/generic
function using a map/hash without changing some/all the implementations
and interfaces up the instantiation tree (am I right?). Obviously this
may not be possible, for example in large a multi-team or multi
language project. If you changed from a map to a hash, you'd have
to change all the interfaces to pass the hashing function instead
or as well as the comparison operator.
In Ada, a private (nonlimited) generic formal type guarantees
an equality operation and assignment is defined for the type.
These are the only logical requirements for an associative array.
I guess an efficient hash/map library could be written for
private nonlimited generic formals, but neither std::map nor
hashed maps meet this less restrictive requirement.
Put another way, neither language has minimally restrictive
associative arrays in their (or their standard library) specification.