title: std::set custom comparator for 2D points
body: <p>I need a list of non-duplicated 2D points, so I use a <code>std::set</code> with a custom comparison function. The function I use has problems after inserting points because sometimes the <code>std::find</code> does not find the already inserted points.</p>
  
  <pre><code>const double tolerance = 0.1;
  struct MyPoint2D
  {
    MyPoint2D(double x, double y) : _x(x), _y(y) {}
    double _x, _y;
  };
  auto compMyPoint2D = [&amp;](const MyPoint2D&amp; pointA, const MyPoint2D&amp; pointB) -&gt; bool
  {
    if (pointA._x &lt; pointB._x - tolerance) return true;
    if (pointA._x &gt; pointB._x + tolerance) return false;
    if (pointA._y &lt; pointB._y - tolerance) return true;
    return false;
  };
  std::set&lt;MyPoint2D, decltype(compMyPoint2D)&gt; orderedMyPoints(compMyPoint2D);
  MyPoint2D pointA(0.66,1.14);
  MyPoint2D pointB(0.75, 0.0);
  MyPoint2D pointC(0.57,1.19);
  orderedMyPoints.insert(pointA);
  orderedMyPoints.insert(pointB);
  orderedMyPoints.insert(pointC);
  if (orderedMyPoints.find(pointC)==orderedMyPoints.end())
  {
    std::cout &lt;&lt; "Not found" &lt;&lt; std::endl;
    orderedMyPoints.insert(pointC);
    if (orderedMyPoints.find(pointC)==orderedMyPoints.end())
      std::cout &lt;&lt; "Still not found" &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>Would I need to preorder the 2d points before inserting into the <code>std::set</code> or there is a better comparison function for 2d points?</p>
  
  <p>I need to use <code>std::find</code> after inserting all points to obtain the final point indexes.</p>
  
  <p>I'm using native C++ on Microsoft Visual Studio 2010.</p>