fork download
  1. #include <algorithm> // for std::find(), std::remove_if()
  2. #include <array> // for std::array
  3. #include <iostream> // for console output
  4. #include <vector> // for std::vector
  5.  
  6. typedef std::array<int, 3> Point3D;
  7.  
  8. std::ostream& operator<<(std::ostream& os, const Point3D& point)
  9. {
  10. os << "{" << point[0] << ", "
  11. << point[1] << ", " << point[2] << "}";
  12.  
  13. return os;
  14. }
  15.  
  16. std::ostream& operator<<(std::ostream& os, const std::vector<Point3D>& v)
  17. {
  18. if (v.empty())
  19. {
  20. os << "{ <empty> }" << std::endl;
  21. return os;
  22. }
  23.  
  24. os << "{\n";
  25. for (const auto& point : v)
  26. {
  27. os << " " << point << '\n';
  28. }
  29. os << "}" << std::endl;
  30. return os;
  31. }
  32.  
  33. int main()
  34. {
  35. std::vector<Point3D> objPoints{{1, 2, 3},
  36. {4, 5, 6},
  37. {11, 22, 33},
  38. {44, 55, 66},
  39. {77, 88, 99}};
  40.  
  41. std::vector<Point3D> delPoints{{10, 10, 10},
  42. {11, 22, 33},
  43. {44, 55, 66}};
  44.  
  45.  
  46. std::cout << "objPoints =\n" << objPoints << std::endl;
  47. std::cout << "delPoints =\n" << delPoints << std::endl;
  48.  
  49. objPoints.erase(
  50. std::remove_if(
  51. objPoints.begin(),
  52. objPoints.end(),
  53. [&delPoints](const Point3D& point)
  54. {
  55. // Erasing condition:
  56. // Is 'point' contained in the 'delPoints' vector?
  57. auto it = std::find(delPoints.begin(), delPoints.end(), point);
  58. return (it != delPoints.end());
  59. }),
  60. objPoints.end());
  61.  
  62. std::cout << "\nAfter erasing, objPoints =\n";
  63. std::cout << objPoints << std::endl;
  64. }
  65.  
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
objPoints =
{
  {1, 2, 3}
  {4, 5, 6}
  {11, 22, 33}
  {44, 55, 66}
  {77, 88, 99}
}

delPoints =
{
  {10, 10, 10}
  {11, 22, 33}
  {44, 55, 66}
}


After erasing, objPoints =
{
  {1, 2, 3}
  {4, 5, 6}
  {77, 88, 99}
}