C++ primer, 5th, 14.8.2, Using a Library Function Object with the Algorithms:
vector<string *> nameTable; // vector of pointers
// error: the pointers in nameTable are unrelated, so < is undefined
sort(nameTable.begin(), nameTable.end(),
[](string *a, string *b) { return a < b; });
// ok: library guarantees that less on pointer types is well defined
sort(nameTable.begin(), nameTable.end(), less<string*>());
Then I checked the std::less implementation:
template<typename _Tp>
struct less : public binary_function<_Tp, _Tp, bool>
{
bool
operator()(const _Tp& __x, const _Tp& __y) const
{ return __x < __y; }
};
I found out that std::less also use operator < to do the work, so why < is undefined and library guarantees that less on pointer types is well defined, why is std:less recommended, and why is std::less better than <.