Maybe you can try this:
struct PAIR : std::pair<int, int>
{
using std::pair<int, int>::pair;
};
int main(int argc, char* argv[]) {
std::vector<std::pair<int, int>> data;
std::copy(data.begin(), data.end(), std::ostream_iterator<PAIR>(std::cout, "\n"));
return 0;
}
Since there's already a good answer, I will simply quote the link:
The problem is that the name lookup does not find your
operator<<(ostream& os, const PAIR& r). The code that tries to invoke
the operator<< is in somewhere inside the ostream_iterator<> which is
itself inside the std namespace. The name lookup looks around for the
right function inside ostream_iterator<> and the std namespace; the
argument dependent lookup does not help here because both of the
parameters are in the std namespace, too.
So, my suggestion is (1) either to wrap your operator into namespace
std { }, but that is UB, IIRC. Or (2) create a struct inheriting from
std::pair to define a new type in your namespace, and using the ADL to
find your operator<<().
Usage:
#include <iostream>
#include <limits>
#include <vector>
#include <iterator>
#include <map>
std::ostream& operator<<(std::ostream& o, const std::pair<int, int>& p) {
o << p.first << p.second;
return o;
}
struct PAIR : std::pair<int, int>
{
using std::pair<int, int>::pair;
};
int main(int argc, char* argv[]) {
std::vector<std::pair<int, int> > data;
data.push_back(std::pair<int, int>(50, 42));
std::copy(data.begin(), data.end(), std::ostream_iterator<PAIR>(std::cout, "\n"));
return 0;
}