c++ - boost::bind or boost::lambda on std::lower_bound -
c++ - boost::bind or boost::lambda on std::lower_bound -
suppose want utilize std::lower_bound on std::vector of pointers this:
struct x { int x; double y; }; // overloads normal comparisons bool operator< (int left, const x& right) { homecoming left < right.x; } bool operator< (const x& left, int right) { homecoming left.x < right; } std::vector<x*> v; int searchvalue = 5; std::vector<x*>::iterator = std::lower_bound(v.begin(), v.end(), searchvalue, ? // heck set here? );
would utilize boost::bind or boost::lambda here, , if so, how?
i think this:
std::lower_bound(v.begin(), v.end(), searchvalue, searchvalue < *_1);
however illegal indirection error on this.
try following
struct mylessthan { bool operator()( const x* xval, int ival ) { homecoming xval->x < ival; } }; std::vector<x*> v; int searchvalue = 5; std::vector<x*>::iterator = std::lower_bound(v.begin(), v.end(), searchvalue, mylessthan() );
that should work.
c++ boost
Comments
Post a Comment