Date: Wed, 15 Apr 2020 10:38:45 -0400
On 4/15/20 10:13 AM, Edward Diener via Std-Discussion wrote:
> In C++17 if a std::hash specialization for a key is not provided and is
> therefore considered a disabled specialization, is it a compiler error
> if an unordered associate container is instantiated with that key ?
>
> As an example:
>
> struct MyStruct
> {
> int x;
> long y;
> MyStruct(int a, long b) : x(a), y(b) {}
> };
>
> /* No std::hash specialization is provided for MyStruct */
>
> MyStruct my1(1,2);
>
> std::unordered_set<MyStruct> oname;
> oname.insert(my1);
>
> Should the code cause a compilation error in C++17 and above ?
>
>
>
http://eel.is/c++draft/container.requirements#unord.req-3 implies that
the Hash type must meet the Cpp17Hash requirements. A disabled std::hash
specialization does not meet the Cpp17Hash requirements, as is stated at
http://eel.is/c++draft/unord.hash#2.note-1 .
> In C++17 if a std::hash specialization for a key is not provided and is
> therefore considered a disabled specialization, is it a compiler error
> if an unordered associate container is instantiated with that key ?
>
> As an example:
>
> struct MyStruct
> {
> int x;
> long y;
> MyStruct(int a, long b) : x(a), y(b) {}
> };
>
> /* No std::hash specialization is provided for MyStruct */
>
> MyStruct my1(1,2);
>
> std::unordered_set<MyStruct> oname;
> oname.insert(my1);
>
> Should the code cause a compilation error in C++17 and above ?
>
>
>
http://eel.is/c++draft/container.requirements#unord.req-3 implies that
the Hash type must meet the Cpp17Hash requirements. A disabled std::hash
specialization does not meet the Cpp17Hash requirements, as is stated at
http://eel.is/c++draft/unord.hash#2.note-1 .
-- Jason Cobb
Received on 2020-04-15 09:41:43