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

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

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?
Jul 23 '05 #1
2 2681
On Tue, 29 Mar 2005 11:15:22 +0200 in comp.lang.c++, "qfel"
<[q_tmp]@[aster.pl]> wrote,
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.

Jul 23 '05 #2
In article <42*********************@mamut2.aster.pl>,
"qfel" <[q_tmp]@[aster.pl]> wrote:
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
Jul 23 '05 #3

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

Similar topics

25
by: Christopher Benson-Manica | last post by:
If you liked the functionality of std::map, but found that you couldn't trust your implementation to handle nonstandard data structures, how would you code a wrapper? I've produced the following:...
4
by: int2str | last post by:
Hi! Given the following code: #include <map> #include <string> #include <cassert> int main() {
4
by: vineoff | last post by:
What kind of user-defined compare-function should be passed to std::map as a template argument? Like: std::map<foo, bar, cmp> map; Question 2: Is std::map resorted after every...
4
by: Raider | last post by:
Is there std::map member-function that do as code below? typedef std::map<NameClass, ValueClass> ParameterContainer; .... // this code is equivalent to "_Parameters = Value", // but a bit...
1
by: Siegfried Heintze | last post by:
Should the following work? It does on some compilers. How can I get it to work on g++ 3.2? On g++ 3.2 it keeps telling me that there is no such function operator << for ostream and...
3
by: tezheng | last post by:
since std::map is some kind of std::set<std::pair> can i use "set_difference" with std::map? how to deal with the "operator =" of std::pair<T1, T2>, as T1 and T2 could be various type.
4
by: ulaskaraoz | last post by:
Hi, I have a std::map instance that I want to save into harddisk so that I donot have to recompute it each time. The map itself is keyed by a string and the values are pointers to other objects....
4
by: bb | last post by:
Hi, void fun(const std::map<std::string,int>& m1) { // How to make a case insensitive search of this map without making a copy? } cheers.
7
by: guido | last post by:
Hi, I'm looking for a container class that can map whole ranges of keys to objects - something like std::map, but not only for individual values for the key, but for whole ranges. Example: I...
6
by: Juha Nieminen | last post by:
joseph cook wrote: Not always. By default, yes, but you can specify other comparators, eg: std::map<int, int, std::greaterreversedMap;
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
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$) { } ...
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...
0
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...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.