Skip to content
This repository has been archived by the owner on Dec 26, 2023. It is now read-only.

is_transparent is not working #86

Open
bredelings opened this issue Jul 23, 2020 · 1 comment
Open

is_transparent is not working #86

bredelings opened this issue Jul 23, 2020 · 1 comment
Assignees
Labels

Comments

@bredelings
Copy link

Hi,

I tried using robin_hood::unordered_map, and its really nice! However, I tried using the is_transparent interface, and it almost works, but does not quite work: It looks like this is because you are putting std::hash into a wrapper.

I defined std::hash to accept a type BUILD_args_ref in addition to the keytype BUILD_args. This all works OK, except that robin_hood::hash doesn't accept my extra hashkey type! You can see this here:

../../source/otc/robin_hood.h:1322:39: error: cannot convert ‘const BUILD_args_ref’ to ‘const BUILD_args&’
 1322 |         *idx = Mix{}(WHash::operator()(key));
      |                      ~~~~~~~~~~~~~~~~~^~~~~

I made a quick hack that fixed this:

// A thin wrapper around std::hash, performing an additional simple mixing step of the result.
template <typename T>
struct hash : public std::hash<T> {
    
    size_t operator()(T const& obj) const
        noexcept(noexcept(std::declval<std::hash<T>>().operator()(std::declval<T const&>()))) {
        // call base hash
        auto result = std::hash<T>::operator()(obj);
        // return mixed of that, to be save against identity has
        return hash_int(static_cast<uint64_t>(result));
    }

    template <typename K>
    size_t operator()(K const& obj) const
        noexcept(noexcept(std::declval<std::hash<T>>().operator()(std::declval<K const&>()))) {
        // call base hash
        auto result = std::hash<T>::operator()(obj);
        // return mixed of that, to be save against identity has
        return hash_int(static_cast<uint64_t>(result));
    }
};

I am not sure if this is sufficiently careful, but it seems to work.

@martinus
Copy link
Owner

Hi, thanks for finding! I'll see what I can do, but I unfortunately currently don't have much time for this project

@martinus martinus self-assigned this Jul 30, 2020
@martinus martinus added the bug label Jul 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants