请看一下 Johannes Schaub 发布的示例,对向量对进行排序:
如何根据对的第二个元素对向量对进行排序? https://stackoverflow.com/questions/279854/how-do-i-sort-a-vector-of-pairs-based-on-the-second-element-of-the-pair/280128#280128
std::sort(a.begin(), a.end(),
boost::bind(&std::pair<int, int>::second, _1) <
boost::bind(&std::pair<int, int>::second, _2));
我以为我确实理解 boost::bind,但我在这方面遇到了麻烦。
问题一:
排序算法需要谓词函数作为第三个参数。我在这里看到的是一个布尔表达式。我缺少什么?:
boost::bind(&std::pair<int, int>::second, _1) < boost::bind(&std::pair<int, int>::second, _2)
boost::bind 库是否为这两个绑定重载了operator
问题2:
这让我很困惑:
boost::bind(&std::pair<int, int>::second, _1)
通常有某种函数指针作为绑定调用的第一个参数,但这里它是类成员的地址?该特定绑定的结果是什么?
感谢您的时间和帮助