Overload operator >> für std :: pair <int, int>

Ich versuche, @ zu verwendboost::lexical_cast auf einenstd::pair<int, int>.

#include <iostream>
#include <utility>
#include <boost/lexical_cast.hpp>

namespace my
{
  // When my_pair is a user defined type, this program compiles
  // and runs without any problems.
  // When declaring my_pair as an alias of std::pair<int, int>,
  // it fails to compile

  /*
  struct my_pair
  {
      int first;
      int second;
  };
  */

  using my_pair = std::pair<int, int>;

  std::istream& operator>>(std::istream& stream, my_pair& pair)
  {
    stream >> pair.first;
    stream >> std::skipws;
    stream >> pair.second;
    return stream;
  }
}

int main()
{
  my::my_pair p = boost::lexical_cast<my::my_pair>("10 10");
  std::cout << p.first << " " << p.second << std::endl;
  return 0;
}

Wenn ich richtig verstehe, muss sich der Operator >> im gleichen Namespace wie my_pair befinden, damit ADL funktioniert.

ies würde zu undefiniertem Verhalten führen, da dem Namespace std Funktionen hinzugefügt würden.

Ich möchte Vererbung vermeiden, wie instruct my_pair : std::pair<int, int>.

Was könnte die Lösung für dieses Problem sein?

Ich verwende clang ++ - 3.6 unter OS X.

Antworten auf die Frage(6)

Ihre Antwort auf die Frage