template <class T,class S> struct pair_equal_to : binary_function <T,pair<T,S>,bool> { bool operator() (const T& y, const pair<T,S>& x) const { return x.first==y; } };
To find the right int value, you should use the following:
int find_me = 1;
For instance:
int main() { vector< pair <int, char> > myVec; pair<int,char> p1 = make_pair(1,'a'); pair<int,char> p2 = make_pair(2,'b'); pair<int,char> p3 = make_pair(1,'c'); myVec.push_back(p1); myVec.push_back(p2); myVec.push_back(p3); vector< pair <int, char> >::iterator it = find_if(myVec.begin(),myVec.end(),bind1st(pair_equal_to<int,char>(),1)); if (it == myVec.end()) { cout << "not found\n"; } else { cout<< "found - first instance is < " << it->first <<"," << it->second << " >"; } return 0; }
Yakov source share