Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support std::hash #59

Closed
krojew opened this issue Mar 13, 2018 · 4 comments · Fixed by #67
Closed

Support std::hash #59

krojew opened this issue Mar 13, 2018 · 4 comments · Fixed by #67
Assignees
Milestone

Comments

@krojew
Copy link

krojew commented Mar 13, 2018

boost::uuids::uuid now supports only boost:hash via hash_value(), making it an unnecessary dependency on platforms supporting >= c++11. There also should be a std::hash specialization.

@jeking3
Copy link
Collaborator

jeking3 commented Mar 13, 2018

Hi, thanks for reporting the issue. Can you add any more details or examples?

@jeking3 jeking3 self-assigned this Mar 13, 2018
@krojew
Copy link
Author

krojew commented Mar 13, 2018

A typical usage example would be using uuid as the key for std::unordered_map. Since uuid already supports boost::hash, it would be nice to also support std::hash, to make that example work without changing the default hasher. In other words, what's missing is a std::hash specialization for uuid.

@jeking3
Copy link
Collaborator

jeking3 commented Mar 26, 2018

If you can provide a simple code example of this that I could build into a unit test for C++11 or later, I would appreciate it.

@jeking3 jeking3 added this to the v1.68.0 milestone Mar 26, 2018
@krojew
Copy link
Author

krojew commented Mar 26, 2018

A simple example can be:

#include <unordered_set>
#include <boost/uuid.hpp>

// make this compile
std::unordered_set<boost::uuids::uuid> set;

A fast solution can be the use of existing boost::hash_value:

namespace std
{
    template<>
    struct hash<boost::uuids::uuid>
    {
        std::size_t operator ()(const boost::uuids::uuid &value) const noexcept
        {
            return boost::hash_value(value);
        }
     };
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants