473,569 Members | 2,879 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1511
"Neil Zanella" <nz******@cs.mu n.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
2374
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 another, bigger container. I had the definition of my auxiliary containers based on pointers, but considered using iterators instead. I know iterators...
1
1352
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 elements in these containers are sorted. However, the (soon-to-be standard) hash-based containers are also considered associative. In these...
7
1694
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 from the container as fast as possible. So far I have been using std::map to store the files, whereas the key was a unique file ID. That given, I could...
8
7680
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 this: sType = "String"
2
1589
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, say. When an item is to be inserted/removed into/from these custom containers, customNew and customDelete is called.
2
5737
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 point of performance as well, I know that it is hard to answer because this is dependent on the application that you would like to develop :-)) ) ...
1
1794
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 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1745.pdf. Now I'm not sure how to interpret a requirement relating to exception safety. It says in 6.3.1.1: "For unordered associative...
5
1868
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
1530
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 can use only a subset of the algorithms on associative containers. The problem is that key in an associative container is const. Hence, any...
0
7619
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7930
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6290
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.