469,357 Members | 1,839 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,357 developers. It's quick & easy.

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 4586

"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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Tanguy Fautré | last post: by
9 posts views Thread by Dennis Jones | last post: by
3 posts views Thread by He Shiming | last post: by
3 posts views Thread by Przemek | last post: by
1 post views Thread by placid | last post: by
4 posts views Thread by Nick Keighley | last post: by
4 posts views Thread by sks | last post: by
1 post views Thread by Saile | last post: by
1 post views Thread by ambarish.mitra | last post: by
20 posts views Thread by puzzlecracker | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.