mercredi 5 juin 2019

Create a set_difference vector from two maps

Currently I am getting the set difference of two maps and then iterating through the resulting map.

Ideally I want to create a vector of the difference instead of a map. That way I iterate more efficiently.

typedef std::map<int, Info> RegistrationMap;

RegistrationMap redundantRegs;
std::set_difference(map1.begin(), map1.end(), map2.begin(), map2.end(), 
std::inserter(redundantRegs, redundantRegs.begin()),
    [](const std::pair<int, Info> &p1, const std::pair<int, Info> &p2 {return p1.first < p2.first;});

for (auto reg : redundantRegs)
{
    map2[hiu.first].Status = "delete";
}

How would you create a vector of the set difference instead? Can this be done within the set_difference function?

I'm looking for the most efficient way possible of getting the difference.

Aucun commentaire:

Enregistrer un commentaire