Skip to content

Instantly share code, notes, and snippets.

@viksit
Created April 8, 2010 03:52
Show Gist options
  • Save viksit/359756 to your computer and use it in GitHub Desktop.
Save viksit/359756 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <map>
using namespace std;
template <typename K, typename V, class C, class A>
ostream &operator<< (ostream &os, map<K,V,C,A> const& m)
{
os << "{ ";
typename map<K,V,C,A>::const_iterator p;
for (p = m.begin(); p != m.end(); ++p) {
os << p->first << ":" << p->second << ", ";
}
return os << "}";
}
int main (int argc, char *argv[])
{
typedef map<int, string> Map1;
typedef map<double, Map1> Map2;
Map2 m;
m.insert (make_pair (1.2, Map1 ()));
m[1.2].insert (make_pair (3, "three"));
m[1.2].insert (make_pair (5, "five"));
m.insert (make_pair (.5, Map1 ()));
m[.5].insert (make_pair (5, "five"));
m[.5].insert (make_pair (1, "one"));
m[.5].insert (make_pair (9, "nine"));
cout << m << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment