【发布时间】:2014-06-13 21:27:08
【问题描述】:
我用模板写了一些类:
template <class T, class Allocator = ::std::allocator<T> >
class my_list;
我应该为这个类写 ::std::hash specializtion。我怎样才能做到这一点? 简单的偏特化:
namespace std {
template <class T, class Allocator>
class hash<my_list<T, Allocator> >{
public :
size_t operator()(const my_list<T, Allocator> &x ) const{
return ...;
}
};
}
但我不能写简单的偏特化,因为它被 C++ ISO 禁止:
ISO/IEC 14882 第三版 2011-09-01
17.6.4.2.1 命名空间标准 [namespace.std]
2 如果 C++ 程序声明......标准库类或类模板的任何成员类模板的显式或部分特化,则其行为未定义。
我能做什么?
【问题讨论】:
标签: c++ templates c++11 std language-lawyer