I have two vector that are related. The vector have the same size and their content match 1:1 in the sense that it could be refactores into a single vector of some struct. I am trying to remove the duplicates on the first vector, and this should match in the second vector.
v1 = [5 4 3 7 6 5 2 3]
v2 = [0 1 2 3 4 5 6 7]
Since 5 and 3 are repeated in v1
, the result should be
v1 = [5 4 3 7 6 2]
v2 = [0 1 2 3 4 6]
The order can be change, as long as the relation is the same.
I am trying to achieve this using range-v3 library.
std::vector<unsigned int> v1;
std::vector<double> v2;
auto v1Andv2 = range::views::zip(v1, v2);
ranges::sort(v1Andv2)
// ranges::unique(v1Andv2) // Doesnt compile
auto lastIt = std::unique(std::begin(v1Andv2), std::end(v1Andv2), [](const auto &a, const auto &b) {
// Since the second value of the zip is a double and could be slightly different,
// I am only interested in first one
return std::get<0>(a) == std::get<0>(b);
});
v1.erase(???, std::end(v1));
v2.erase(???, std::end(v2));
I have no idea what I should put in the ??? to get the iterator each value in the zip. Also, why is ranges::actions::unique not working in this case?