associative containers: requirements

Discussion in 'C++' started by Neil Zanella, Oct 17, 2003.

  1. Neil Zanella

    Neil Zanella Guest

    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
     
    Neil Zanella, Oct 17, 2003
    #1
    1. Advertising

  2. "Neil Zanella" <> 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
     
    Victor Bazarov, Oct 17, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?=

    Iterators as associative containers' key

    =?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?=, Jun 26, 2003, in forum: C++
    Replies:
    2
    Views:
    779
    =?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?=
    Jun 26, 2003
  2. Dave
    Replies:
    3
    Views:
    417
    Kevin Goodsell
    Apr 19, 2004
  3. utab
    Replies:
    2
    Views:
    498
    Daniel T.
    Mar 12, 2006
  4. yonil
    Replies:
    1
    Views:
    317
  5. desktop
    Replies:
    5
    Views:
    408
    James Kanze
    Jun 26, 2007
Loading...

Share This Page