#include <algorithm> // for std::find(), std::remove_if()
#include <array> // for std::array
#include <iostream> // for console output
#include <vector> // for std::vector
typedef std::array<int, 3> Point3D;
std::ostream& operator<<(std::ostream& os, const Point3D& point)
{
os << "{" << point[0] << ", "
<< point[1] << ", " << point[2] << "}";
return os;
}
std::ostream& operator<<(std::ostream& os, const std::vector<Point3D>& v)
{
if (v.empty())
{
os << "{ <empty> }" << std::endl;
return os;
}
os << "{\n";
for (const auto& point : v)
{
os << " " << point << '\n';
}
os << "}" << std::endl;
return os;
}
int main()
{
std::vector<Point3D> objPoints{{1, 2, 3},
{4, 5, 6},
{11, 22, 33},
{44, 55, 66},
{77, 88, 99}};
std::vector<Point3D> delPoints{{10, 10, 10},
{11, 22, 33},
{44, 55, 66}};
std::cout << "objPoints =\n" << objPoints << std::endl;
std::cout << "delPoints =\n" << delPoints << std::endl;
objPoints.erase(
std::remove_if(
objPoints.begin(),
objPoints.end(),
[&delPoints](const Point3D& point)
{
// Erasing condition:
// Is 'point' contained in the 'delPoints' vector?
auto it = std::find(delPoints.begin(), delPoints.end(), point);
return (it != delPoints.end());
}),
objPoints.end());
std::cout << "\nAfter erasing, objPoints =\n";
std::cout << objPoints << std::endl;
}
I2luY2x1ZGUgPGFsZ29yaXRobT4gICAgLy8gZm9yIHN0ZDo6ZmluZCgpLCBzdGQ6OnJlbW92ZV9pZigpCiNpbmNsdWRlIDxhcnJheT4gICAgICAgIC8vIGZvciBzdGQ6OmFycmF5CiNpbmNsdWRlIDxpb3N0cmVhbT4gICAgIC8vIGZvciBjb25zb2xlIG91dHB1dAojaW5jbHVkZSA8dmVjdG9yPiAgICAgICAvLyBmb3Igc3RkOjp2ZWN0b3IKCnR5cGVkZWYgc3RkOjphcnJheTxpbnQsIDM+IFBvaW50M0Q7CgpzdGQ6Om9zdHJlYW0mIG9wZXJhdG9yPDwoc3RkOjpvc3RyZWFtJiBvcywgY29uc3QgUG9pbnQzRCYgcG9pbnQpCnsKICAgIG9zIDw8ICJ7IiA8PCBwb2ludFswXSA8PCAiLCAiIAogICAgICAgPDwgcG9pbnRbMV0gPDwgIiwgIiA8PCBwb2ludFsyXSA8PCAifSI7CgogICAgcmV0dXJuIG9zOwp9CgpzdGQ6Om9zdHJlYW0mIG9wZXJhdG9yPDwoc3RkOjpvc3RyZWFtJiBvcywgY29uc3Qgc3RkOjp2ZWN0b3I8UG9pbnQzRD4mIHYpIAp7CiAgICBpZiAodi5lbXB0eSgpKQogICAgewogICAgICAgIG9zIDw8ICJ7IDxlbXB0eT4gfSIgPDwgc3RkOjplbmRsOwogICAgICAgIHJldHVybiBvczsKICAgIH0KICAgIAogICAgb3MgPDwgIntcbiI7CiAgICBmb3IgKGNvbnN0IGF1dG8mIHBvaW50IDogdikKICAgIHsKICAgICAgICBvcyA8PCAiICAiIDw8IHBvaW50IDw8ICdcbic7CiAgICB9CiAgICBvcyA8PCAifSIgPDwgc3RkOjplbmRsOwogICAgcmV0dXJuIG9zOwp9CgppbnQgbWFpbigpCnsKICAgIHN0ZDo6dmVjdG9yPFBvaW50M0Q+IG9ialBvaW50c3t7MSwgMiwgM30sIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHs0LCA1LCA2fSwgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgezExLCAyMiwgMzN9LCAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB7NDQsIDU1LCA2Nn0sIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHs3NywgODgsIDk5fX07CgogICAgc3RkOjp2ZWN0b3I8UG9pbnQzRD4gZGVsUG9pbnRze3sxMCwgMTAsIDEwfSwgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgezExLCAyMiwgMzN9LCAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB7NDQsIDU1LCA2Nn19OwogICAgCiAgICAKICAgIHN0ZDo6Y291dCA8PCAib2JqUG9pbnRzID1cbiIgPDwgb2JqUG9pbnRzIDw8IHN0ZDo6ZW5kbDsKICAgIHN0ZDo6Y291dCA8PCAiZGVsUG9pbnRzID1cbiIgPDwgZGVsUG9pbnRzIDw8IHN0ZDo6ZW5kbDsKICAgIAogICAgb2JqUG9pbnRzLmVyYXNlKAogICAgICAgIHN0ZDo6cmVtb3ZlX2lmKAogICAgICAgICAgICBvYmpQb2ludHMuYmVnaW4oKSwgCiAgICAgICAgICAgIG9ialBvaW50cy5lbmQoKSwgCiAgICAgICAgICAgIFsmZGVsUG9pbnRzXShjb25zdCBQb2ludDNEJiBwb2ludCkKICAgICAgICAgICAgeyAKICAgICAgICAgICAgICAgIC8vIEVyYXNpbmcgY29uZGl0aW9uOgogICAgICAgICAgICAgICAgLy8gSXMgJ3BvaW50JyBjb250YWluZWQgaW4gdGhlICdkZWxQb2ludHMnIHZlY3Rvcj8KICAgICAgICAgICAgICAgIGF1dG8gaXQgPSBzdGQ6OmZpbmQoZGVsUG9pbnRzLmJlZ2luKCksIGRlbFBvaW50cy5lbmQoKSwgcG9pbnQpOwogICAgICAgICAgICAgICAgcmV0dXJuIChpdCAhPSBkZWxQb2ludHMuZW5kKCkpOwogICAgICAgICAgICB9KSwgCiAgICAgICAgb2JqUG9pbnRzLmVuZCgpKTsKCiAgICBzdGQ6OmNvdXQgPDwgIlxuQWZ0ZXIgZXJhc2luZywgb2JqUG9pbnRzID1cbiI7CiAgICBzdGQ6OmNvdXQgPDwgb2JqUG9pbnRzIDw8IHN0ZDo6ZW5kbDsKfQo=
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}
}