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! 5 4695
"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.
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.
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?
"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.
"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! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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;
|
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...
|
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,
|
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,...
|
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();
|
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...
|
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...
|
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;...
|
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...
|
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:
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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...
| |