c++ - C2535 with template-class in unordered_map (Microsoft Visual Studio 2015 CTP6) -


i'm getting strange c2535-compiler error while trying compile following code:

template<int number> class container { public:     bool operator==(const container& other) const { return true; } };  namespace std {     template <int number>     class hash<container<number>> {     public:         size_t operator()(const container<number> & state) const {             return 0;         }     }; }  int main(int argc, char* argv[]){     auto* b = new std::unordered_map< container<1>, int>(); //c2535 } 

note if use own template-based hasher

template<int number> class hash { public:     size_t operator()(const container<number> & state) const {         return 0;     } };  int main(int argc, char* argv[]){     auto* b = new std::unordered_map< container<1>, int, hash<1>>(); } 

the code compiles fine. , remember code being compiled without hitch in visual studio 2013 express.

question: vs 2015 - bug or behaviour in way standard-conforming?

actually, made ill-formed subtlety in §14.5.1/4:

in a redeclaration, partial specialization, explicit specialization or explicit instantiation of class template, the class-key shall agree in kind original class template declaration (7.1.6.3).

and, according §20.9/2, hash declared as

header <functional> synopsis

// 20.9.12, hash function primary template: template <class t> struct hash; 

hence try

template <int number> struct hash<container<number>> { /*…*/ }; 

instead.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -