标签:style blog http color io os ar sp div
less主要是重载了operator()方法,用来比较lhs 和 rhs
std::less::operator()
bool operator()(const T &lhs, const T &rhs) const;
constexpr bool operator()(const T &lhs, const T &rhs) const ;
内部实现:
constexpr bool operator()(const T &lhs, const T &rhs) const
{
return lhs < rhs;
}
如果lhs比rhs小,就返回true;如果lhs比rhs大,就返回false;
例子:
#include <functionl> #include <iostream> using namespace std; template <typename A, typename B, typename U = less<int>> bool m(A a, B b, U u = U()) { return u(a,b); } int main() { cout << less<int>()(10, 12) <<eendl; cout << less<int>()(12, 10) << endl; cout << m(10, 12) << endl; }
输出结果:
true
false
true
标签:style blog http color io os ar sp div
原文地址:http://www.cnblogs.com/457220157-FTD/p/4018742.html