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

Enable noexcept for special member functions #64

Merged
merged 3 commits into from
Sep 14, 2024
Merged

Conversation

pfent
Copy link
Contributor

@pfent pfent commented Aug 18, 2024

The hopscotch_hash container already was nothrow move constructible, but was missing the conditional noexcept for the default constructor, swap, and move assignment.

@Tessil
Copy link
Owner

Tessil commented Aug 26, 2024

Thanks for the PR.

It looks good but the default constructor could still throw even with DEFAULT_INIT_BUCKETS_SIZE == 0 as the Hash, KeyEqual and GrowthPolicy default constructors could potentially throw. We would need to add some check on these.

The hopscotch_hash container already was nothrow move constructible,
but was missing the conditional noexcept for the default constructor,
swap, and move assignment.
This adds a helper to detect the default growth policies that are
noexcept when default initialized with 0.
@pfent
Copy link
Contributor Author

pfent commented Aug 27, 2024

Thanks for the review, you raised a valid point:
The default growth policies are not trivially noexcept, so I added a small helper to help detect that the growth policies are actually noexcept when initialized with zero.

@Tessil
Copy link
Owner

Tessil commented Sep 9, 2024

Sorry for the delay.

The change looks good now, thanks.

Just a minor question, could we create a default hopscotch_hash constructor with the noexcept checks and then for the default constructors of (b)hopscotch_map/set check the noexcept of the hopscotch_hash constructor (and call it)? Mainly to avoid all the duplication of the checks.

This avoids duplication of is_nothrow_default_constructible checks.
@pfent
Copy link
Contributor Author

pfent commented Sep 10, 2024

Good point. I moved the checks to hopscotch_hash, which makes the overall diff a bit smaller.

@Tessil
Copy link
Owner

Tessil commented Sep 12, 2024

Thanks, looks good.

Currently the library is compatible with C++11 (it was so when designed and kept like that) but std::is_nothrow_swappable requires C++17.

I'll move the library and tests to C++17 over the weekend as there's no real reason to keep C++11 compatibility and merge the change then.

@Tessil Tessil merged commit 5ca49e3 into Tessil:master Sep 14, 2024
2 of 11 checks passed
@Tessil
Copy link
Owner

Tessil commented Sep 14, 2024

I merged the changes. Note that I had to disable the test_noexcept test on MSVC as std::list is not std::is_nothrow_move_constructible in their implementation. Generally this overflow list should be empty (there need to be > 62 collisions on the same bucket for it to fill), but it's still blocking noexcept on MSVC. I have to check if there's eventually an alternative.

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

Successfully merging this pull request may close these issues.

2 participants