Skip to content

Instantly share code, notes, and snippets.

@yifu
Created September 18, 2012 15:08
Show Gist options
  • Save yifu/3743644 to your computer and use it in GitHub Desktop.
Save yifu/3743644 to your computer and use it in GitHub Desktop.
#include <algorithm>
#include <iostream>
#include <iterator>
#include <map>
#include <utility>
using namespace std;
typedef map<int,int> my_map;
// WARNING: Altering the std namespace is UB.
// Is specializing ostream_iterator<> for std::pair<int,int> the proper form?
namespace std
{
ostream& operator << (ostream& os, const my_map::value_type& right)
{
return os << "[" << right.first << "," << right.second<< "]";
}
}
int main()
{
cout << "Hello world." << endl;
my_map source;
source.insert(make_pair(1,1));
source.insert(make_pair(2,2));
source.insert(make_pair(3,3));
my_map destination;
destination.insert(make_pair(2,465));
destination.insert(source.begin(), source.end());
copy(destination.begin(), destination.end(),
ostream_iterator<my_map::value_type> (cout,", "));
cout << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment