根据20.8.5§1,std::less
是类模板与一个成员函数:为什么std :: less类模板?
template<typename T>
struct less
{
bool operator()(const T& x, const T& y) const;
// ...
};
这意味着我有当我实例化模板,例如std::less<int>
提类型。为什么不是std::less
是一个带有成员函数模板的普通类?
struct less
{
template<typename T, typename U>
bool operator()(const T& x, const U& y) const;
// ...
};
然后,我可以简单地传递std::less
到不带类型参数的算法,这可能会很麻烦。
这仅仅是出于历史原因,因为早期的编译器(据推测)不能很好地支持成员函数模板(或者甚至可能),还是有更深刻的东西呢?
'std :: string a; std :: less()(a,“HI”);'(参见'std :: lower_bound') –
C++ 14将包含一个特殊化,以使std :: less <>()完全转发。参见[N3421](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3421.htm),我认为这是我在波特兰未经修改而采用的。 –
@MooingDuck'std :: less()(a,“HI”)'在我的系统上是'true',这是一个问题吗? – fredoverflow