Skip to content

decltype support #30

@MathieuDutSik

Description

@MathieuDutSik

The following code does not compile:


#include <sparsehash/dense_hash_map>
#include
int main(int argc, char* argv[])
{
auto hash_fct=[&](size_t eVal) -> size_t {
return std::hash<size_t>()(eVal % 128);
};
auto equal_fct=[&](size_t eVal1, size_t eVal2) -> bool {
return eVal1 == eVal2;
};
google::dense_hash_map<size_t, size_t, decltype(hash_fct), decltype(equal_fct)> V({}, hash_fct, equal_fct);
for (size_t i=0; i<10; i++) {
size_t& group = V[i];
}
}


Error is no matching function for call to ‘swap( for both the hash and equality functions.

Replacing "google::dense_hash_map" by "std::unordered_map" makes the code compiles.

As it happen this is only annoying, not blocking. The "solution" is to std::function<size_t(size_t)> hash_fct instead of auto hash_fct. Also, replace decltype(hash_fct) by std::function<size_t(size_t)>. Of course do similarly for the equality test.

But that is annoying and maybe there is a better solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions