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

Section: 22.5.1 [system_error.syn] Status: C++17 Submitter: Tim Song Opened: 2016-05-03 Last modified: 2017-07-30

Priority: 3

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 22.5.1 [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 22.5.6 [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).