C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: C++17 std::hash disabled specializations
From: Jason Cobb (jason.e.cobb_at_[hidden])
Date: 2020-04-15 09:38:45


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 .

-- 
Jason Cobb

STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups