Created
September 18, 2012 15:08
-
-
Save yifu/3743644 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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