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: 03/14/05


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.

-- 
Adrian


Relevant Pages

  • Re: [OT] Re: Teaching new tricks to an old dog (C++ -->Ada)
    ... > supplementary template parameter. ... not passed in and built up, you can't instantiate the map/hash. ... These are the only logical requirements for an associative array. ...
    (comp.lang.ada)
  • Re: template compile errors
    ... gcc throws some strange linking errors. ... code for a template doesn't really exist until you instantiate it... ... compiler generates another set of code and data specific to those types. ...
    (comp.lang.cpp)
  • Undefined reference to ...
    ... txTask.C:: undefined reference to ... As far as i inderstand if we try to instantiate a template class apart ...
    (Debian-User)
  • Re: Template Functions
    ... Templates need to be fully visible to the compiler when it generates ... When you don't have an explicit instantiation, ... it is unable to instantiate ... the template, i.e. create the code for that function. ...
    (microsoft.public.vc.language)
  • Re: name binding from one template to another
    ... compiler binds another referred template from one template in the ... The compiler can look up primary template itself in the first phase - ... I am wrong that compiler will do nothing to bind the referred ... compiler won't instantiate vector until it has to instantiate func. ...
    (microsoft.public.vc.language)