So the problem is the following, I have a multiset where I use the std::equal_to operator for comparing the elements, but when I use the count() method it says all 4 elements in my multiset are equal_to my counts parameter.
std::multiset< std::string, std::equal_to< std::string > > mset;
mset.insert("C++");
mset.insert("SQL");
mset.insert("Jav");
mset.insert("C");
for(std::multiset<std::string>::iterator it = mset.begin(); it != mset.end(); ++it){
std::cout << *it << std::endl;
}
std::cout << std::endl;
std::cout << mset.count("STR");
The output is : 4
If i understand right whats happening is "STR"=="C++"=="SQL"=="Jav"=="C"==true. And this is what I don't understand.
Thankyou for the help.
As BobTFish already said in a comment, the
Compare
type ofstd::multiset
should returntrue
if the first argument is "less" (has to be ordered before) the second argument. The default type isstd::less<Key>
.