-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Remove unnecessary friend
keywords
#2974
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
Conversation
Note that I didn't remove it for `internal\catch_optional.hpp` for ` friend bool operator==(Optional<T>,Optional<T>)` and `operator!=` since the friend function will allow for implicit conversions which allows comparing against a `T`
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## devel #2974 +/- ##
==========================================
- Coverage 91.01% 90.98% -0.03%
==========================================
Files 198 198
Lines 8599 8599
==========================================
- Hits 7826 7823 -3
- Misses 773 776 +3 🚀 New features to boost your workflow:
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
friend
declaration in C++ has two reasons
- To access the internals of a class
- To declare a hidden friend
While it is annoying that to get 2) you also have to have 1), 2) is desirable enough to keep the functions as hidden friends even if they do not need access to the class internals.
Yea, I guess it can be removed for friended functions declared out of line since hidden friends only work if it is defined inline. I will update my pr. |
Oh! I didn't know that, you can close my pr. |
Note that I didn't remove it for
internal\catch_optional.hpp
forfriend bool operator==(Optional<T>,Optional<T>)
andoperator!=
since the friend function will allow for implicit conversions which allows comparing against aT
likeCatch::Optional<int>() == int(1)
nor did I make inline functions not inline likeoperator<<
forITransientExpression
.This change removes several friend declarations that are no longer necessary. Overuse of friend can lead to tighter coupling between classes, reduced encapsulation and thinking it relies on implementation details.
in general avoid granting excessive access unless explicitly required.