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

Add additional heterogeneous overloads. #63

Merged
merged 3 commits into from
Jun 16, 2024

Conversation

BenKaufmann
Copy link
Contributor

  • Add heterogeneous overloads for try_emplace, insert_or_assign, and operator[] to {b}hopscotch_map and hopscotch_hash.

  • Similar overloads were added to the standard associative containers with C++26 (see P2363R5).

* Add heterogeneous overloads for try_emplace, insert_or_assign, and
  operator[] to {b}hopscotch_map and hopscotch_hash.

* Similar overloads were added to the standard associative containers
  with C++26 (see P2363R5).
@Tessil
Copy link
Owner

Tessil commented May 26, 2024

Thanks, it looks good.

Few comments:

  • Would it be possible to also add the changes for the (b)hopscotch_set that are in the P2363R5?
  • For the comment with P2363R5, could we use the This overload only participates in the overload resolution if... instead for all these new methods?
  • At the time heterogeneous overloads were added to the project (2017), only std::map/set had these in the standard. The std::unordered_map/set ones were added in C++20.
    I used the same convention as std::map, requiring has_is_transparent<KeyEqual> but I didn't check for has_is_transparent<Compare>.
    Ideally this should be changed but I have kept it like that for now to keep backward compatibility.
    Could the new methods also only check has_is_transparent<KeyEqual> for consistency?

Thanks

* Add heterogeneous insert overloads to {b}hopscotch_set.
* Adjust doc comment on new overloads.
* Replace std::is_convertible_v with std::is_convertible::value in
  try_emplace overloads as the former was only added in C++17.
* Simplify tests.
@BenKaufmann
Copy link
Contributor Author

Few comments:

* Would it be possible to also add the changes for the `(b)hopscotch_set`  that are in the P2363R5?

Done.

* For the comment with P2363R5, could we use the `This overload only participates in the overload resolution if...` instead for all these new methods?

Done.

* At the time heterogeneous overloads were added to the project (2017), only `std::map/set` had these in the standard. The `std::unordered_map/set` ones were added in C++20.
  I used the same convention as `std::map`, requiring `has_is_transparent<KeyEqual>` but I didn't check for `has_is_transparent<Compare>`.
  Ideally this should be changed but I have kept it like that for now to keep backward compatibility.
  Could the new methods also only check `has_is_transparent<KeyEqual>` for consistency?

I don't think that we can remove the is_convertible check from the try_emplace overloads as otherwise,
try_emplace(K&& k, Args&&... args) and try_emplace(const_iterator hint, K&& k, Args&&... args) are ambiguous. However, I adjusted the code such that it no longer uses std::is_convertible_v.

@Tessil
Copy link
Owner

Tessil commented Jun 9, 2024

Thank you for the change and sorry for the delay.

I don't think that we can remove the is_convertible check from the try_emplace overloads as otherwise,
try_emplace(K&& k, Args&&... args) and try_emplace(const_iterator hint, K&& k, Args&&... args) are ambiguous. However, I adjusted the code such that it no longer uses std::is_convertible_v.

Sorry, I meant to only have has_is_transparent<KeyEqual> as is transparent check and not has_is_transparent<Compare> but keep all other necessary checks (is_convertible). Could you check to put them back? Thanks!

I just want to avoid incoherences in the API were some heterogeneous methods require only has_is_transparent<KeyEqual> but other require has_is_transparent<KeyEqual> & has_is_transparent<Compare>.

@BenKaufmann
Copy link
Contributor Author

Sorry, I meant to only have has_is_transparent<KeyEqual> as is transparent check and not has_is_transparent<Compare> but keep all other necessary checks (is_convertible). Could you check to put them back? Thanks!

I just want to avoid incoherences in the API were some heterogeneous methods require only has_is_transparent<KeyEqual> but other require has_is_transparent<KeyEqual> & has_is_transparent<Compare>.

Sorry, I'm not sure I can follow:

  • I did not remove the is_convertible checks. I only changed my previous use of std::is_convertible_v (added with C++17) to a C++11 compatible std::is_convertible<...>::value under the assumption that this library should work with a C++11 standard-compliant compiler.
  • I added has_is_transparent<Compare> in some places precisely to avoid further incoherences. Both bhopscotch_map.h and bhopscotch_set.h already require has_is_transparent<Compare> in the existing heterogeneous functions, like .e.g. erase(). So, for consistency, I also added this requirement to the new functions.

Could you please clarify your concerns so that I can update this PR again if needed?

@Tessil
Copy link
Owner

Tessil commented Jun 10, 2024

Sorry if I was unclear, it seems some std::is_convertible were removed (example) even though they are part of P2363R5. Is there any reason why they were removed?

* Restore std::is_convertible<K&&, iterator> constraint.
@BenKaufmann
Copy link
Contributor Author

it seems some std::is_convertible were removed [...] Is there any reason why they were removed?

Given that iterator is convertible to const_iterator, I assumed that checking for the latter is enough. Of course, this assumption is wrong in the general case. I now restored the previously removed checks and also added a test for the constraints.

@Tessil Tessil merged commit 72d947e into Tessil:master Jun 16, 2024
9 of 11 checks passed
@Tessil
Copy link
Owner

Tessil commented Jun 16, 2024

Sorry for the review delay and thanks for your patience.

It looks good to me in general. Just a bit worried about the static int inst in heterogeneous_test if we ever want to run the tests in parallel, but it isn't supported by Boost.Test currently anyway. It can always be changed later.

I merged the change.

Thanks again for your contribution.

@BenKaufmann
Copy link
Contributor Author

Just a bit worried about the static int inst in heterogeneous_test if we ever want to run the tests in parallel, but it isn't supported by Boost.Test currently anyway. It can always be changed later.

I understand your concern and drafted an alternative approach: master...BenKaufmann:hopscotch-map:simplify-unit-tests.

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