[英]Can I replace boost::bind with bind1st/2nd?
為了更好地理解,我可以用std :: bind1st / 2nd替換下面示例中對boost :: bind的調用嗎? 還是因為返回參考而不可能?
實施例(縮短):
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 );
...
這是不可能的,因為bind1st
和bind2nd
不像bind
那樣重載operator==
(產生另一個函子)。 如果不想使用bind
,則需要自己編寫函子或使用lambda。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.