std::map operator[] and default values of build-in types

Q

qfel

If new pair is inserted into std::map through operator[], is default value
for build-in types equal to 0?
eg.
std::map<std::string,bool> m;
bool b=m["not existing key"];
will b equal to false, or will it contain undefined value?
 
D

David Harmon

On Tue, 29 Mar 2005 11:15:22 +0200 in comp.lang.c++, "qfel"
If new pair is inserted into std::map through operator[], is default value
for build-in types equal to 0?
Yes.

eg.
std::map<std::string,bool> m;
bool b=m["not existing key"];
will b equal to false, or will it contain undefined value?

The std containers go to some effort to avoid undefined values.
 
H

Howard Hinnant

qfel said:
If new pair is inserted into std::map through operator[], is default value
for build-in types equal to 0?
eg.
std::map<std::string,bool> m;
bool b=m["not existing key"];
will b equal to false, or will it contain undefined value?

b will be false.

-Howard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,661
Latest member
sxarexu

Latest Threads

Top