473,394 Members | 1,700 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,394 software developers and data experts.

map and multimap

al
When should use multimap?

map template is as below:

namespace std {
template<class Key, class T, class Pred, class A>
class map;

What are "class Pred" and "class A" for?

When not to use STL at all?

Thanks!

Jul 22 '05 #1
5 4696

"al" <al***@168.net> wrote in message news:CE***********************@bgtnsc04-news.ops.worldnet.att.net...
What are "class Pred" and "class A" for?
Map's are ordered containers. Pred is the "predicate" function for providing
that ordering. It's defaulted to "less" which just uses < (which works for any
type that defines that).

A is the allocator function which provides memory for the container's dynamic
parts. Again, this is defaulted and unless you spefically need to control where
things get allocated, you can just leave it defaulted.

When not to use STL at all?

It's rare I don't use the standard library. I'm not even sure what you are
asking by that question.
Jul 22 '05 #2
al wrote:
When should use multimap?

When you want to allow duplicate keys.

<snip> When not to use STL at all?


When your implementation is broken (or missing) and you aren't allowed
to upgrade.

Jacques.

Jul 22 '05 #3
al
Ron Natalie <ro*@sensor.com> wrote in message
news:3f***********************@news.newshosting.co m...

"al" <al***@168.net> wrote in message news:CE***********************@bgtnsc04-news.ops.worldnet.att.net...
What are "class Pred" and "class A" for?
Map's are ordered containers. Pred is the "predicate" function for

providing that ordering. It's defaulted to "less" which just uses < (which works for any type that defines that).

A is the allocator function which provides memory for the container's dynamic parts. Again, this is defaulted and unless you spefically need to control where things get allocated, you can just leave it defaulted.

Thanks a lot!

Is A really a function since is "class A"? Why is it needed to provide
memory for the container?

vector has a member function, reserve(). Is it always necessary to call it
when creating a vector container?


Jul 22 '05 #4

"al" <al***@168.net> wrote in message news:y8***********************@bgtnsc04-news.ops.worldnet.att.net...
]> Is A really a function since is "class A"? Why is it needed to provide
memory for the container?
No, it's a class. I mispoke. Every time you add stuff to the container, it
is copied into it. The memory has to come from somewhere.
vector has a member function, reserve(). Is it always necessary to call it
when creating a vector container?


Nope, it's not normally necessary to call it at all. It just tells the vector, hey
allocate enough memory for this many all at once so you won't have to do it
piece meal as I add things to the vector.

Jul 22 '05 #5

"al" <al***@168.net> wrote in message
news:CE***********************@bgtnsc04-news.ops.worldnet.att.net...
When should use multimap?

map template is as below:

namespace std {
template<class Key, class T, class Pred, class A>
class map;

What are "class Pred" and "class A" for?
As a good rule of thumb never ever look at the standard headers.
They are not designed to be self documenting and may include extensions to
the standard which, if you use them, will make your code non-portable (In
particular I believe that implementations are allowed to add additional
defaulted template parameters).

This warning is particularly relevant to using the STL as alot of stuff is
not defined in the header at all such as what it means to be an acceptable
iterator to an STL algorithm - this is a particular problem of all
templates - they are largely defined by descriptions of behaviour rather
than code.

If you do the right thing and read the docs/manual pages then you will not
have to ask questions like this and you will write portable, standard
compliant C++.

If you are just poking around for curiosity's sake then I suggest you look
at http://www.dinkumware.com/refxcpp.html which gives the documentation for
dinkumwares C++ library implementation. This isn't a definition of the
standard but it is probably close enough for you.

When not to use STL at all?

If you're compiler is lousy at inlining then the STL generated code will be
truly awful (too many trivial function calls).
I had a conflict once where I was not supposed to use optimization and yet
the compiler would not inline enough without it. In the end I got a waiver
to turn optimization on.
Thanks!

Jul 22 '05 #6

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

Similar topics

12
by: Tanguy Fautré | last post by:
Hello, does std::multimap make any guarantee about the insertion order? for example: int main() { std::multimap<int, int> Map;
9
by: Dennis Jones | last post by:
Hi, Is there a way to iterate through a multimap in such a way as to encounter only the unique keys? In other words, since a multimap allows duplicate keys, I would like to iterate through the...
3
by: He Shiming | last post by:
Hi Folks, Happy holidays! I have a question regarding STL multimap. Basically, the current multimap<int,int> look like this: key=>value 1=>10, 1=>20, 1=>30,
3
by: Przemek | last post by:
All, what is the efficient way to find all distinct keys in a multimap. I use the code template<class T1, class T2> set<T1> GetDistinctKeys(multimap<T1, T2> nMap) { T1 temp; multimap<T1,...
1
by: placid | last post by:
Hi all, i was just wondering if i have a class class A {}; then i want to use a multimap like, multimap<string,A*> as; //can i have a pointer to a A object ? A* aa = new A();
4
by: Nick Keighley | last post by:
Hi, I've checked out various documentation for multimap but can't find anywhere it explicitly stated that insert() invalidates multimap iterators. consider this pseudo code:- int...
4
by: sks | last post by:
I have a question regarding std::multimap/iterators. At the SGI website, it says "Erasing an element from a multimap also does not invalidate any iterators, except, of course, for iterators that...
1
by: Saile | last post by:
I want to give an array the values from the specific multimap's key's values. multimap<string,int> mymultimap; multimap<string,int>::iterator it;...
1
by: ambarish.mitra | last post by:
Hi all, I have a multimap, where key is an int and the value is a class. I can insert into the multimap, but finding it difficult to retrieve the value when keys match. I can do this with...
20
by: puzzlecracker | last post by:
I am using while loop for that but I am sure you can do it quicker and more syntactically clear with copy function. Here is what I do and would like to if someone has a cleaner solution: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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...
0
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...

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.