First, I have the following two objects, both filled with data:
std::vector<std::map<std::uint8_t, std::uint8_t>> x1;
std::vector<std::map<std::uint8_t, std::uint8_t>> x2;
My objective is to search inside x2
(by the key), checking if any value from x1
doesn't exist inside x2
, and then erase it from x1
.
I tried with the following code snippet, but to no avail (it doesn't compile!):
for (auto i = x1.begin(); i != x1.end(); ++i)
{
auto it = std::find(x2.begin(), x2.end(), i);
if (it == x2.end())
{
x1.erase(i);
}
}
What am I doing wrong? Could you please share some insights on how to solve this problem?