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

decltype support #30

Open
MathieuDutSik opened this issue Dec 4, 2019 · 0 comments
Open

decltype support #30

MathieuDutSik opened this issue Dec 4, 2019 · 0 comments

Comments

@MathieuDutSik
Copy link

MathieuDutSik commented Dec 4, 2019

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.

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

No branches or pull requests

1 participant