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

Noexcept for hashing function objects #1480

Closed
danpovey opened this issue Mar 7, 2017 · 9 comments
Closed

Noexcept for hashing function objects #1480

danpovey opened this issue Mar 7, 2017 · 9 comments

Comments

@danpovey
Copy link
Contributor

danpovey commented Mar 7, 2017

I've never really used noexcept, but apparently it's important for hashing functions:

http://stackoverflow.com/questions/13580823/sigfpe-when-accessing-unordered-map

I hope someone can look into this.
Kaldi has various hashing function objects, see stl-utils.h.

@danpovey
Copy link
Contributor Author

@dogancan, do you have time to look at this?

@dogancan
Copy link
Contributor

Not at the moment but I can look into it when I have the chance. That might take a while though. From a cursory glance, the idea is to annotate any function that cannot throw with noexcept, right?

@danpovey
Copy link
Contributor Author

danpovey commented Mar 24, 2017 via email

@dogancan
Copy link
Contributor

Oh yeah that's what I meant to ask. There is some further info in the GCC manual and this blog post.

TLDR; C++ standard requires erase and swap operations to be non-throwing. libc++ and libstdc++ implementations of unordered (multi)map/set need access to hash values for these operations. If hash function can throw, it cannot be called by these operations, hence hash values for all items need to be stored along with the items. If hash function is "fast", or if these operations are rare, then storing hash values is wasteful.

@danpovey
Copy link
Contributor Author

danpovey commented Mar 24, 2017 via email

@danpovey
Copy link
Contributor Author

@tomkocse, do you have time for this?

@jtrmal
Copy link
Contributor

jtrmal commented Mar 24, 2017 via email

@tomkocse
Copy link
Contributor

I can start to do this on Monday.

@danpovey
Copy link
Contributor Author

danpovey commented Apr 2, 2017

resolved in #1519

@danpovey danpovey closed this as completed Apr 2, 2017
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

4 participants