samedi 21 juillet 2018

How to get a subset of comparing two vectors of pairs?

How to get a third vector which is to be a subset of comparing two vectors of pairs if two or more of the pairs int's (first) are a subset of each vector.

const std::vector<std::pair<int, MyObj>> lhs; 
const std::vector<std::pair<int, MyObj>> rhs; 

The result by comparing vectorA and vectorB:

vectorA
    pair(1, obj1)
    pair(2, obj2)
    pair(3, obj3)
    pair(4, obj4)

vectorB
    pair(2, obj2)
    pair(4, obj4)
    pair(5, obj5)
    pair(6, obj6)

Should result in vectorC containing:

pair(2, obj2)
pair(4, obj4)

I've been looking at std::set_intersection, but couldn't see how to do this with pairs.

Aucun commentaire:

Enregistrer un commentaire