假设我想在一个std使用std :: LOWER_BOUND ::指针的载体是这样的:的boost ::绑定或升压::性病拉姆达:: LOWER_BOUND
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?
);
我会使用boost ::绑定或提升:: lambda在这里,如果是这样,如何?
我认为这将是这样的:
std::lower_bound(v.begin(), v.end(), searchValue, searchValue < *_1);
但是我在这得到一个非法间接错误。
Boost.Lambda因为[Boost.Phoenix(http://www.boost.org/libs/phoenix/)V3的发布正式弃用,所以_real_答案是使用Boost.Phoenix。也就是说,你使用Boost.Phoenix的代码没有任何改变(除了'operator <'的参数是反向的)。 – ildjarn
通常我会说'std :: less()',但是你将'int'与'X'进行比较,这样就无法工作。 –
Flexo
不幸的是,我仍然在提升1.43,所以Boost.Phoenix不可用:( – syvex