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

enums as values in std::map

hello,

I had a doubt regarding the handling of enums in std::map.
Consider the following piece of code:

------
#include<iostream>
#include<map>
using namespace std;
typedef enum {
UNINITIALIZED,
MEANINGFUL_1,
MEANINGFUL_2
}code;

typedef enum {
O_UNINITIALIZED = 100,
O_MEANINGFUL_1,
O_MEANINGFUL_2
}another_code;

int main(){
map<string,codecodetta;
map<string,another_codecoda;
cout<<codetta["unset"]<<endl;
cout<<coda["unset"]<<endl;
}
------

Is it ok to assume that for both maps, the data-value returned for all
unset key-values will -always- be 0?

thanks for your time,

Mar 20 '07 #1
2 3895
aiooua wrote:
hello,

I had a doubt regarding the handling of enums in std::map.
Consider the following piece of code:

------
#include<iostream>
#include<map>
using namespace std;
typedef enum {
UNINITIALIZED,
MEANINGFUL_1,
MEANINGFUL_2
}code;

typedef enum {
O_UNINITIALIZED = 100,
O_MEANINGFUL_1,
O_MEANINGFUL_2
}another_code;

int main(){
map<string,codecodetta;
map<string,another_codecoda;
cout<<codetta["unset"]<<endl;
cout<<coda["unset"]<<endl;
}
------

Is it ok to assume that for both maps, the data-value returned for all
unset key-values will -always- be 0?

thanks for your time,
Depending on what your code["unset"] is...your answer will be different.
However, it's certain that: UNINITIALIZED = 0, O_UNINITIALIZED = 100

Fei
Mar 20 '07 #2
On Mar 20, 9:38 am, "aiooua" <aio...@gmail.comwrote:
hello,

I had a doubt regarding the handling of enums in std::map.
Consider the following piece of code:

------
#include<iostream>
#include<map>
using namespace std;
typedef enum {
UNINITIALIZED,
MEANINGFUL_1,
MEANINGFUL_2

}code;

typedef enum {
O_UNINITIALIZED = 100,
O_MEANINGFUL_1,
O_MEANINGFUL_2

}another_code;

int main(){
map<string,codecodetta;
map<string,another_codecoda;
cout<<codetta["unset"]<<endl;
cout<<coda["unset"]<<endl;}

------

Is it ok to assume that for both maps, the data-value returned for all
unset key-values will -always- be 0?

thanks for your time,
I think you are correct but don't quote me on it. The right question
is
what is the default initialization of an enum.

Search this group for "default initialize enum" for some relevant
threads.
Some quote the relevant portions of the standard.

Mar 20 '07 #3

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

Similar topics

3
by: Woodster | last post by:
I have declared the following std::map<std::string, std::string> myMap; to pass myMap to functions should I be declaring functions as: void function(std::map<std::string, std::string>); ...
2
by: Serengeti | last post by:
Hello, in my class I have a map that translates strings to pointers to some member functions. The code goes like this: class F { typedef void (Function::*MathFuncPtr)(); std::map<std::string,...
1
by: Saeed Amrollahi | last post by:
Dear All C++ Programmers Hello I am Saeed Amrollahi. I am a software engineer in Tehran Sewerage Company. I try to use std::map and map::find member function. I use Visual Studio .NET. my...
19
by: Erik Wikström | last post by:
First of all, forgive me if this is the wrong place to ask this question, if it's a stupid question (it's my second week with C++), or if this is answered some place else (I've searched but not...
3
by: Dan Trowbridge | last post by:
Hi everyone, In my attempt to port code from VS 6.0 to VS.NET I had some code break along the way, mostly due to not adhereing closely to the C++ standard. This may be another instance but I...
1
by: Avery Fong | last post by:
The following program will result in a compile error when building under Debug but will compile under Release. Why does is work under Release mode but not under Debug This program is developed...
13
by: kamaraj80 | last post by:
Hi I am using the std:: map as following. typedef struct _SeatRowCols { long nSeatRow; unsigned char ucSeatLetter; }SeatRowCols; typedef struct _NetData
5
by: Yannick Tremblay | last post by:
Hi, I have a std::map<id, timestampcollection. The id is the normal reference so the key-value ordering is correct. However, once in a blue moon, I want to prune this collection. So that...
2
by: digz | last post by:
Hi, I am trying to write a program which has two threads one of them write to a map , and the other one deletes entries based on a certain criterion.. first I cannot get the delete portion to...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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...
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
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
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...

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.