stl map with bool values: set default value to false

R

Rui Maciel

Let's say we have a stl map with bool values. Is it possible to set it such that,
if we pass to operator[] a key which doesn't have a value, the operator will return
false instead of true? If so, can anyone please explain me how that can be done?


Thanks in advance,
Rui Maciel
 
V

Victor Bazarov

Rui said:
Let's say we have a stl map with bool values. Is it possible to set it such that,
if we pass to operator[] a key which doesn't have a value, the operator will return
false instead of true? If so, can anyone please explain me how that can be done?

It is the default behaviour. Now, making it so it sets it to 'true'
would be a small challenge. Also, see FAQ 5.2.

V
 
R

Rui Maciel

Victor said:
It is the default behaviour. Now, making it so it sets it to 'true'
would be a small challenge. Also, see FAQ 5.2.

It appears I was getting odd results due to a bug in my code. I was using a
std::map<size_t,bool> to store object selection entries and the selection routine
was so overreaching that it ended up selecting all objects in the domain, which led
to all map entry values to appear as true.


Thanks for the help, Victor. Kudos!
Rui Maciel
 

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

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top