You would need to define a custom operator==
to loop over Pins
and pinNumNameMap (incidentally, I just answered another question about comparing custom objects in a vector here).
Here is what I came up with, although it might not be exactly what you need depending on whether you need all the entries in Pins
and pinNumNameMap
to match exactly or if comparing the size of the containers is enough.
EDIT: I merged the two sections into one to illustrate the possible use.
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <functional>
struct myObject
{
int numberOfSymbols;
std::list<int> symbolNumbers;
std::list<int> Pins;
std::list<std::string> pinNumList;
std::map<std::string, std::string> pinNumNameMap;
friend bool operator == (const myObject& _this, const myObject& _other)
{
// Check if entry sizes match
if (_this.Pins.size() != _other.Pins.size() ||
_this.pinNumNameMap.size() != _this.pinNumNameMap.size())
{
return false;
}
// Now check if the things inside the entries also match
bool same(true);
for (auto this_it = _this.Pins.begin(), other_it = _other.Pins.begin(); this_it != _this.Pins.end(); ++this_it, ++other_it)
{
same &= (*this_it == *other_it);
}
for (const auto& name : _this.pinNumNameMap)
{
same &= (_other.pinNumNameMap.find(name.first) != _other.pinNumNameMap.end() &&
_other.pinNumNameMap.at(name.first) == name.second);
}
return same;
}
};
// std::reference_wrapper is used when you want to
// store references to objects in a container like
// std::vector (you can't store myObject&)
typedef std::reference_wrapper<myObject> ObjRef;
int main()
{
std::vector<myObject> m_myObject;
// This is your comparison object.
// Use this to identify objectsin the original
// container with matching Pins and pinNumNameMaps.
myObject tmp;
tmp.Pins = {1, 2, 3};
tmp.pinNumNameMap =
{
{"pin 1", "name 1"},
{"pin 2", "name 2"},
{"pin 3", "name 3"}
};
std::vector<ObjRef> objectsWithCertainPins;
for (auto& obj : m_myObject)
{
if (obj == tmp)
{
// Use std::reference_wrapper to avoid
// copying large myObject instances
objectsWithCertainPins.emplace_back(std::ref(obj));
}
}
// Now you can iterate over objects in your
// objectsWithCertainPins container.
for (auto& obj : objectsWithCertainPins)
{
std::cout << "Pins:";
for (const auto& p : obj.get().Pins)
{
std::cout << " " << p;
}
std::cout << "\n";
}
return 0;
}