Suppose I want to use std::lower_bound on a std::vector of pointers like this:
struct X {
int x;
double y;
};
// overloads for normal comparisons
bool operator< (int left, const X& right) { return left < right.x; }
bool operator< (const X& left, int right) { return left.x < right; }
std::vector<X*> v;
int searchValue = 5;
std::vector<X*>::iterator it = std::lower_bound(v.begin(), v.end(), searchValue,
? // what the heck do I put here?
);
Would I use boost::bind or boost::lambda here, and if so, how?
I would think it would be like this:
std::lower_bound(v.begin(), v.end(), searchValue, searchValue < *_1);
However I get an illegal indirection error on this.
Got it after some trial and error. Boost.Bind won’t work here and the compiler will get confused on with placeholder to use. Boost.Bind uses _1 in an anonymous root namespace. Boost.Lambda uses it under the namespace boost::lambda::_1.
Also, I had the order wrong with the comparisons.