Problem by erasing duplicates from vector

I have this vector intersects, which stores the coordinates of intersection points (xyz-coordinates). Because I receive duplicates I want to erase this duplicates.
Normally I do this with this code:

1
2
3
4
std::vector<std::array<double, 3>> intersects;

std::sort(intersects.begin(), intersects.end(), sorting_intersects);
intersects.erase(std::unique(intersects.begin(), intersects.end()), intersects.end());


But here not all duplicates are erased. I also tried this code
1
2
3
std::set<array<double, 3>> set2(intersects.begin(), intersects.end());
			
intersects.erase(std::remove_if(intersects.begin(), intersects.end(), [&set2] (array<double, 3> item) {return !set2.erase(item); }), intersects.end());

But still there are some duplicates left.
Last edited on
Please post the definition of sorting_intersects.
std::array<> is LessThanComparable if its value_type is LessThanComparable
http://en.cppreference.com/w/cpp/container/array/operator_cmp

Use the non-predicate version of std::sort
1
2
3
// std::sort(intersects.begin(), intersects.end(), sorting_intersects);
std::sort(intersects.begin(), intersects.end() );
intersects.erase(std::unique(intersects.begin(), intersects.end()), intersects.end());

http://coliru.stacked-crooked.com/a/744225bef06a1555
Topic archived. No new replies allowed.