比方說,我們有下面的類:定義的std ::哈希類模板的枚舉成員
template <int i>
class S {
public:
enum class E : signed char {a, b, c};
// ...
};
現在我想爲E.散列函數以下工作:
namespace std {
template<>
struct hash<typename S<3>::E> {
size_t operator()(typename S<3>::E const& e) const { return 0; }
};
}
但是,如果我讓一般它不會:
namespace std {
template<int i>
struct hash<typename S<i>::E> {
size_t operator()(typename S<i>::E const& e) const { return 0; }
};
}
// error C2764: 'i': template parameter not used or deducible in partial specialization 'std::hash<S<i>::E>'
我怎樣才能確保始終能夠哈希的s :: E代表所有我?
如果所有的'S '有'E'是其他單一類型的typedef? 「我」無法在一般意義上理解。這不完全相同,但在這裏有一些類似的答案。找到一個:http://stackoverflow.com/questions/6060824/c-template-argument-can-not-be-deduced – chris