473,322 Members | 1,268 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

associative containers: requirements


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

Jul 19 '05 #1
1 1492
"Neil Zanella" <nz******@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
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ney André de Mello Zunino | last post by:
Hello. A non-modifying algorithm I implemented uses two associative containers from STL: set and map. The elements on those containers are supposed to refer to actual elements which lie on...
1
by: Dave | last post by:
Hello all, Why is the term "associative" containter used to describe std::set<>, std::map<>, std::multiset<> and std::multimap<>? I always had the impression that it is related to the fact that...
7
by: Matthias Käppler | last post by:
Hi, I have the following problem: I want to store file objects in a container 8for now, it's not important how they look like). Now, on the one hand I need to be able to randomly pick files...
8
by: Derek Basch | last post by:
Is there any way to associate name/value pairs during an array initialization? Like so: sType = "funFilter" filterTypeInfo = ; filterTypeInfo = new Array("type" : sType); I can do it using...
2
by: bob | last post by:
Hi, Given: 1) Custom containers that have nothing to do with vector, deque, list, map etc, 2) a custom version of new and delete defined for these containers, customNew and customDelete,...
2
by: utab | last post by:
Hi there, Can you please explain me why there are sequential and associative containers in c++ on some examples and briefly specify the advantages of using one over the other(and also from the...
1
by: yonil | last post by:
I hope this is the correct group for this... I'm currently implementing the TR1 associative containers according to specification found in...
5
by: desktop | last post by:
set, map, multiset and multimap are all associative containers. But what does the word "associative" have to do with these 4 containers?
3
by: subramanian100in | last post by:
I am copying the following lines as it is, from Stanley Lippman's C++ Primer 4th edition, page 418(First paragraph). It says: "Although the map and set types provide bidirectional iterators, we...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.