stl - Comparing two multimap objects in c++ -
i need compare 2 multimap objects find out whether equal or not
i know using std::equal can compare 2 vector object equality possible use algorithm comparing multimap objects?
typedef std::multimap<std::string, std::string> headermap; headermap _map,_secmap; _map.insert(headermap::value_type("a", "a")); _map.insert(headermap::value_type("b", "b")); _secmap.insert(headermap::value_type("a", "a")); _secmap.insert(headermap::value_type("b", "b")); **std::equal(_map.begin(),_map.end(),_secmap.begin()); // true?**
if above code snippet not true, how can compare 2 multimap objects?(i don't ant iterate objects , compare keys , values 1 one) thanks
you can compare them operator==
:
map_ == secmap_;
this internally compare elements 1 one until first unequal 1 found. there no way of avoiding that. here working example:
#include <map> #include <string> #include <iostream> int main() { typedef std::multimap<std::string, std::string> headermap; headermap m1, m2, m3; m1.insert(headermap::value_type("a", "a")); m1.insert(headermap::value_type("b", "b")); m2.insert(headermap::value_type("a", "a")); m2.insert(headermap::value_type("b", "b")); m3.insert(headermap::value_type("a", "a")); m3.insert(headermap::value_type("b", "b")); m3.insert(headermap::value_type("c", "c")); std::cout << std::boolalpha; std::cout << (m1==m2) << " " << (m1==m3) << std::endl; }
output:
true false
bear in mind names leading underscores reserved implementation should not use them.
Comments
Post a Comment