Title
[tiny] Defining hash functions for composite user-defined types is annoying
Status
open
Section
[hash.requirements]
Submitter
Matt Austern

Created on 2012-10-23.00:00:00 last changed 139 months ago

Messages

Date: 2013-10-11.23:34:25

We have a hash function for built-in types and for some standard library types, but we don't have automatically generated hash<> specializations for user-defined types like

  struct my_type {
    int x;
    std::string y;
    vector<int> z;
  };
Defining a good and efficient hash function for composite types takes a fair amount of work. One consequence is that there are a lot of user-defined types with bad hash functions floating around. One possibility is automatically generating hash<> specializations, but that's tricky. A simpler possibility is providing tools that make it easier for users to do the right thing.

Bristol 2013: Austern explained that he didn't envision syntax to automate the generation of hash operations but thought that this could potentially be solved by a library. Stroustrup and Austern thought that reflection would be another way to solve this. Van Winkel thought that for the generation of such things, it's perhaps desirable that they aren't generated by default but can be generated on demand when a user-defined type requests such generation. The guidance of the EWG is to propose a solution that handles equality operators and other such things in a more general manner.

EWG expressed long-term interest in this idea in Chicago 2013 for post-C++14. Papers welcome.

History
Date User Action Args
2012-10-23 00:00:00admincreate