bool image_manager::contains_image(const std::string& filename)
{
return this->map_.count(filename);
}
Now the warning I get is:
warning C4800: 'unsigned int' : forcing value to bool 'true' or 'false' (performance warning)
However since the return type of std::maps count() method is:
1 if an element with a key equivalent to x is found, or zero otherwise.
Hence it can be used pretty much like a boolean. So why exactly do I get this warning? In C++ integers can basically be used for boolean checks right? Hence 0 == false and 1 == true. So why does the compiler throw me a warning? I also tried using a static_cast like this:
return static_cast<bool>(this->map_.count(filename));
but I’m still getting the warning.
In general, an
unsigned intis not abool, hence the warning. Try:instead.