【发布时间】:2011-05-10 06:04:45
【问题描述】:
请查看 Johannes Schaub 发布的这个示例,以对向量对进行排序:
How do I sort a vector of pairs based on the second element of the pair?
std::sort(a.begin(), a.end(),
boost::bind(&std::pair<int, int>::second, _1) <
boost::bind(&std::pair<int, int>::second, _2));
我以为我确实了解 boost::bind,但我对这个有问题。
问题 1:
排序算法需要一个谓词函数作为第三个参数。我在这里看到的是一个布尔表达式。我错过了什么?:
boost::bind(&std::pair<int, int>::second, _1) < boost::bind(&std::pair<int, int>::second, _2)
boost::bind 库是否对这两个绑定重载运算符
问题 2:
这让我很困惑:
boost::bind(&std::pair<int, int>::second, _1)
通常有某种函数指针作为绑定调用的第一个参数,但这里是类成员的地址?该特定绑定的结果是什么?
感谢您的时间和帮助
【问题讨论】:
标签: c++ boost-bind