473,898 Members | 3,028 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 1522
"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
2388
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 might become invalid upon certain operations, but as I said, the algorithm is non-modifying. This...
1
1372
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 containers, element order is determined purely by the hash function and the insertion order, not by any...
7
1709
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 pick random files from the container in O(logn). On the other hand, I need functionality to sort...
8
7707
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
1608
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
5749
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 :-)) ) Thanks for all comments in advance.
1
1806
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 containers, if an exception is thrown by any operation other than the container's hash function from within...
5
1886
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
1544
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 algorithm that writes to elements in the sequence cannot be used on an associative container. We may use...
0
9992
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9839
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10853
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10943
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10480
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7187
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4295
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3303
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.