d*******h 发帖数: 642 | | X****r 发帖数: 3557 | 2 Haven't tried myself, but it seems that you want
boost::bind(&A::Compare, _1, x1, x2)
By the way, boost won't make your code faster here, so I don't see
why you want to write code that you don't understand yourself.
d_x2==x2);}
_1, _2)(x1, x2)); // 这里编译不通过
【在 d*******h 的大作中提到】 : class A : { : double d_x1, d_x2; : vector vec; : bool Compare(double x1, double x2) const { return (d_x1==x1 && d_x2==x2);} : public: : A* Find(double x1, double x2) const : { : vector::iterator itor; : itor = find_if(vec.begin(), vec.end(), boost::bind(&A::Compare, _1, _2)(x1, x2)); // 这里编译不通过
| d*******h 发帖数: 642 | 3 thanks, but still got compile error. 还有,不是说使用for_each, find_if这些函
数会比自己用for loop 快一点吗?
【在 X****r 的大作中提到】 : Haven't tried myself, but it seems that you want : boost::bind(&A::Compare, _1, x1, x2) : By the way, boost won't make your code faster here, so I don't see : why you want to write code that you don't understand yourself. : : d_x2==x2);} : _1, _2)(x1, x2)); // 这里编译不通过
| p***o 发帖数: 1252 | 4 这个地方自己写个functor也不费事,要是你的code里就这一个地方用到了boost,
接手你code的人肯定要骂死你。
【在 d*******h 的大作中提到】 : thanks, but still got compile error. 还有,不是说使用for_each, find_if这些函 : 数会比自己用for loop 快一点吗?
| X****r 发帖数: 3557 | 5 我试了一下,是const correctness的问题。你把
std::vector::iterator itor;
改为
std::vector::const_iterator itor;
就可以了。
【在 d*******h 的大作中提到】 : thanks, but still got compile error. 还有,不是说使用for_each, find_if这些函 : 数会比自己用for loop 快一点吗?
| X****r 发帖数: 3557 | 6 里的确有可能会比自己写for loop快,但是对于vector来说我觉得不会有
多少
区别。如果你不是想要学习精通C++,而只是想要用它完成你的工作的话,为了莫须有的
局部性能
而降低代码的可读性和可维护性实在是得不偿失的事情。
【在 d*******h 的大作中提到】 : thanks, but still got compile error. 还有,不是说使用for_each, find_if这些函 : 数会比自己用for loop 快一点吗?
| d*******h 发帖数: 642 | | w***g 发帖数: 5958 | |
|