refactor(tidy): Use C++20 contains method#29191
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
Nice use of tidy! Concept ACK, assuming |
|
Concept ACK |
24238b3 to
f41eaff
Compare
|
Nice! Concept ACK |
BrandonOdiwuor
left a comment
There was a problem hiding this comment.
Concept ACK using ::contains(Key& key) (C++20) to check for elements
|
Can the full diff be reproduced with |
Sorry, my initial push did not pass the tidy check because it seems the I don't have the specific command I used on hand but I used the |
I see, that is a bit unfortunate. I also found some more things to change: sedited@63fcfbe, but not sure if non-tidy changes should be made here tbh. |
f41eaff to
520669e
Compare
Thanks for the commit, I added it. Did you find them manually or with clang-tidy? |
520669e to
90c4d91
Compare
|
I support using
I think I'd prefer removing the clang-tidy check for now and only changing it in places where it doesn't conflict with other PRs, e.g. maybe in tests? And then organically have more |
FWIW I would approve this PR if it would only contain the changes that are automatically picked up by tidy and applied by running with |
Sure, I agree. Closing this pull. |
C++20 introduced the
containsmethod on containers to check if an element is in the container. It can be used instead of thecountmethod now.I believe it is easier to understand, as
containsdirectly returns aboolindicating whether the element exists, whilecountreturns the number of occurrences of the element, which then often needs to be compared against 0.Also, it is slightly more efficient than count for this use-case.
This pull request introduces the clang-tidy check
readability-container-containsand fixes the instances wherecountis being used wherecontainscould be used instead. I used the clang-tidy -fix option to do it automatically.