Skip to content

Instantly share code, notes, and snippets.

@mkamilov
Created November 22, 2017 23:08
Show Gist options
  • Save mkamilov/a74734f877999508b0676fcecaf835ce to your computer and use it in GitHub Desktop.
Save mkamilov/a74734f877999508b0676fcecaf835ce to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;
struct PrimitiveInfo
{
list<int> numbers;
friend bool operator== (PrimitiveInfo &p1, PrimitiveInfo &p2);
};
bool operator== (PrimitiveInfo &p1, PrimitiveInfo &p2)
{
for (list<int>::const_iterator it1=p1.numbers.begin(); it1 != p1.numbers.end(); ++it1) {
list<int>::iterator it2 = find(p2.numbers.begin(), p2.numbers.end(), 1);
if (it2 != p2.numbers.end()) {
// at least one element is found, treat it as equal
cout << "found " << *it1 << endl;
return true;
}
}
cout << "not found" << endl;
return false;
}
bool checkInfo(PrimitiveInfo info, vector<PrimitiveInfo> v2)
{
bool found = false;
vector<PrimitiveInfo>::iterator it = find_if(v2.begin(), v2.end(), info);
// true if info is found in v2
return it != v2.end();
}
int main()
{
vector<PrimitiveInfo> m_symbolPrimitiveList;
vector<PrimitiveInfo> m_newPrimitiveList;
list<int> l1;
l1.push_back(1);
l1.push_back(2);
PrimitiveInfo p1;//{ l1 };
m_newPrimitiveList.push_back(p1);
m_newPrimitiveList.push_back(p1);
//m_symbolPrimitiveList.push_back(p1);
for (int i =0; i < m_newPrimitiveList.size(); i++) {
if (checkInfo(m_newPrimitiveList[i], m_symbolPrimitiveList)) {
// found, do not add
cout << "found. skipp adding" << endl;
}
else
{
cout << "not found, so need to add " << endl;
m_symbolPrimitiveList.push_back(m_newPrimitiveList[i]);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment