All pastes #926970 Raw Edit

Scary multimap behaviour

public text v1 · immutable
·published 2008-03-03 22:52 UTC
rendered paste body
#include <map>
#include <string>
#include <iostream>

struct comparestrings
{
  bool operator()(const std::string & left, const std::string & right) const { return left.compare(right); }
};

main()
{
  std::multimap<std::string, std::string, comparestrings> testmap;
  testmap.insert(std::pair<std::string, std::string>("key1", "value1"));
  std::cerr << testmap.count("key2") << std::endl;    // <-- why does this print "1"?!?!
}