associative containers: requirements

  • Follow


Hello,

I would like to know what the exact requirements are for classes that use 
associative containers in terms of which overloaded operators and 
constructors they must provide. For instance, if I have a class
called Foo, and declare and std::map<Foo>, then what other
methods and constructors must Foo implement for
std::map<Foo> to work as expected besides

bool operator<(const Foo &foo) const;

Thanks,

Neil

0
Reply nzanella (147) 10/17/2003 1:51:34 AM

"Neil Zanella" <nzanella@cs.mun.ca> wrote...
> I would like to know what the exact requirements are for classes that use
> associative containers in terms of which overloaded operators and
> constructors they must provide. For instance, if I have a class
> called Foo, and declare and std::map<Foo>, then what other
> methods and constructors must Foo implement for
> std::map<Foo> to work as expected besides
>
> bool operator<(const Foo &foo) const;

Actually, that is not even a requirement.  You may supply your own
comparator for the keys.  The requirement for the comparator 'comp',
though, is that in order for two keys 'k1' and 'k2' to be _equivalent_,
comp(k1,k2) should be false _as_well_as_ comp(k2,k1).

BTW, you cannot declare std::map<Foo> because std::map needs at least
two template arguments.

Get yourself a copy of Nicolai Josuttis' "The C++ Standard Library".
It will be the best book you've used.  Trust me.

Victor


0
Reply v.Abazarov1 (626) 10/17/2003 4:48:13 AM


1 Replies
39 Views

(page loaded in 0.06 seconds)

Similiar Articles:







7/13/2012 9:23:55 AM


Reply: