0

I am trying to add a specialization to a namespace owned by library 1 for a type in a namespace owned by library 2. For example, in order to use BOOST TEST for std::pair, I have to add

template<class T, class S>   
std::ostream& operator<<(std::ostream&, const std::pair<T,S>& p)

to std or boost::test_tools::tt_detail.

According to cppreference, extending std is not allowed except in a few situations which my problem doesn't seem to fall into. The remaining choice is to extend boost::test_tools::tt_detail. The need to extend a details namespace seems awkward.

Is there anything else that could be done or what should be done in general?

[Edit]

This problem is more than surrounding code in some namespace. Many libraries like to use this technique to let users provide read/write handler for custom types. For example, boost's json library relies on operator>>. My updated question is, what happens if I'd like to use different implementation for different purpose?

Candy Chiu
  • 6,579
  • 9
  • 48
  • 69

0 Answers0