I have something like this:
#include <iostream>
namespace N
{
typedef std::pair<int, double> MyPair;
std::ostream& operator << (std::ostream& o, MyPair const & mypair)
{
///
}
}
int main()
{
N::MyPair pr;
std::cout << pr;
}
This naturally doesn't work, because ADL won't find operator<<
because namespace N
is not associated with MyPair
(unfortunately). Afaik one may not add to namespace std, so if I chose to define operator <<
in std that would be kinda illegal. So... what to do in such situations? I don't want to explicitly qualify operator <<
, nor do I wish to write using namespace N
. So, questions are:
- How to refactor the code?
- Why wouldn't ADL associate namespaces of typedefs? Serious reasons? It would be nice, e.g. in this case. Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…