Questions about boost with a vector of pair
I am trying to write a function with takes a vector of pair and an key (integer). it should return true if the input key matches the FIRST value of the map. bool containsPair(vector< pair<int, int> >& aMap, int key ) { return ( find_if ( aMap.begin(), aMap.end(), bind( equal_to<int>(), boost::lambda::bind( &pair< int, int>::first_type::first, boost::lambda::_1) , key ) ) != aMap.end()); } But i cant' get the code to compile. I have this error: ../RowColumn1_4PatternMatcherHelper.h: In function bool containsPair(std::vector<std::pair<int, int>, std::allocator<std::pair<int, int> > >&, int): ../RowColumn1_4PatternMatcherHelper.h:62: error: struct std::pair<int, int>::first_type is not a class or namespace ../RowColumn1_4PatternMatcherHelper.h:62: error: first was not declared in this scope make: *** [TestDriver.o] Error 1 any help is appreciated. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
yinglcs2@yahoo.com wrote:
I am trying to write a function with takes a vector of pair and an key (integer). it should return true if the input key matches the FIRST value of the map.
bool containsPair(vector< pair<int, int> >& aMap, int key ) { return ( find_if ( aMap.begin(), aMap.end(), bind( equal_to<int>(), boost::lambda::bind( &pair< int, int>::first_type::first, boost::lambda::_1) , key ) ) != aMap.end());
} But i cant' get the code to compile.
Use bind( &pair<int, int>::first, _1 ) == key.
participants (2)
-
Peter Dimov
-
yinglcs2@yahoo.com