I want to use std::find
function along with a predicate (not sure if I use the correct word). Here is the code
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class foo {
public:
typedef pair< int, vector<int> > way;
typedef pair< int, int > index;
typedef pair< index, vector<way> > entry;
vector< entry > table;
void bar()
{
vector<int> v1;
v1.push_back(1);
v1.push_back(2);
way w = make_pair( 1, v1 );
vector<way> v2;
v2.push_back(w);
index id = make_pair( 10, 20 );
entry en = make_pair( id, v2 );
table.push_back( en );
}
void insert()
{
index new_id = make_pair( 10, 20 );
if ( find(table.begin(), table.end(), new_id) != table.end() ) {
// index matched in the table
// then I will push back a new pair (way)
// to the second part of the entry
}
}
};
int main()
{
foo f;
f.bar();
f.insert();
return 0;
}
As you can see, find()
should search the table
based on the first element in each entry. Right now, it says that ==
is not overloaded to compare a pair
.