This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++17 status.

2686. Why is std::hash specialized for error_code, but not error_condition?

Section: 19.5.2 [system.error.syn] Status: C++17 Submitter: Tim Song Opened: 2016-05-03 Last modified: 2021-06-06

Priority: 3

View all other issues in [system.error.syn].

View all issues with C++17 status.

Discussion:

Both error_code and error_condition have an operator< overload, enabling their use in associative containers without having to write a custom comparator.

However, only error_code has a std::hash specialization. So it's possible to have a set<error_code>, a set<error_condition>, an unordered_set<error_code>, but not an unordered_set<error_condition>. This seems...odd.

[2016-08 - Chicago]

Thurs AM: Moved to Tentatively Ready

Proposed resolution:

This wording is relative to N4582.

  1. Edit [system_error.syn], header <system_error> synopsis, as indicated:

    namespace std {
        // ...
    
        // 19.5.6 Hash support
        template<class T> struct hash;
        template<> struct hash<error_code>;
        template<> struct hash<error_condition>;
    
       // ...
    }
    
  2. Edit 19.5.7 [syserr.hash] as indicated:

    template <> struct hash<error_code>;
    template <> struct hash<error_condition>;
    

    -1- The template specializations shall meet the requirements of class template hash (20.12.14).