Help me understand this usage of boost::bind

妖精的绣舞 提交于 2019-12-02 18:45:00

boost::bind overloads the operator ! and the relational and logical operators ==, !=, <, <=, >, >=, &&, ||, so this is why you "see" a boolean expression, but you're really getting back a function predicate.

From there you can see that you're binding the second member of the pair for the 1st and 2nd arguments of the overloaded less than function.

As for your second question: Boost bind will recognize when you have passed a pointer to a member and treat it as if you called

bind<R>(mem_fun(&std::pair<int,int>::second), args);

This is how the documentation describes this:

Using bind with pointers to members

Pointers to member functions and pointers to data members are not function objects, because they do not support operator(). For convenience, bind accepts member pointers as its first argument, and the behavior is as if boost::mem_fn has been used to convert the member pointer into a function object. In other words, the expression

bind(&X::f, args)

is equivalent to

bind(mem_fn(&X::f), args)

where R is the return type of X::f (for member functions) or the type of the member (for data members.)

You can find this and more information here.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!