I'm trying to compile the following code:
#include <boost/geometry/geometries/point_xy.hpp> #include <iostream> #include <utility> typedef boost::geometry::model::d2::point_xy<long> Point; typedef std::pair<Point, Point> Vector; bool operator==(const Point& p1, const Point& p2) { return p1.x() == p2.x() && p1.y() == p2.y(); } int main() { Vector vec1(Point(0,0), Point(1,1)); Vector vec2(Point(0,0), Point(1,2)); std::cout << ((vec1 == vec2) == false) << std::endl; std::cout << ((vec1 == vec1) == true) << std::endl; } VS2012 C++ compiler returns the following compilation error:
...VC\include\utility(219): error C2678: binary '==' : no operator found which takes a left-hand operand of type 'const Point' (or there is no acceptable conversion)
GCC C++ compiler returns the following compilation error:
/usr/include/c++/4.8/bits/stl_pair.h:
In instantiation of ‘bool std::operator==(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&) [with _T1 = boost::geometry::model::d2::point_xy; _T2 = boost::geometry::model::d2::point_xy]’:
test.cpp:22:28: required from here /usr/include/c++/4.8/bits/stl_pair.h:215:51: error:
no match for ‘operator==’ (operand types are ‘const boost::geometry::model::d2::point_xy’ and ‘const boost::geometry::model::d2::point_xy’) { return __x.first == __y.first && __x.second == __y.second; }
Error disappears if I overload == operator for Vector:
bool operator==(const Vector& v1, const Vector& v2) { return v1.first == v2.first && v1.second == v2.second; }
==is defined forstd::pairby the standard library.Pointobjects had been found by ADL, there would not be any need to provide anoperator==forVectors.