[英]Can I replace boost::bind with bind1st/2nd?
Just for better understanding, can I replace the call to boost::bind in the following example with std::bind1st/2nd? 为了更好地理解,我可以用std :: bind1st / 2nd替换下面示例中对boost :: bind的调用吗? Or is it not possible because of returning a reference?
还是因为返回参考而不可能?
Example(shortened): 实施例(缩短):
class Pos
{
public:
bool operator==( const Pos& );
...
}
class X
{
public:
const Pos& getPos() { return m_p; }
...
private:
Pos m_p;
}
...
Pos position;
std::vector<X> v;
std::vector<X>::iterator iter;
...
iter = std::find_if( v.begin(), v.end(), boost::bind( &X::getPos, _1 ) == position );
...
It's not possible, because neither bind1st
nor bind2nd
overloads operator==
like bind
does (to yield another functor). 这是不可能的,因为
bind1st
和bind2nd
不像bind
那样重载operator==
(产生另一个函子)。 If you don't want to use bind
, you need to write the functor yourself, or use a lambda. 如果不想使用
bind
,则需要自己编写函子或使用lambda。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.