-
Notifications
You must be signed in to change notification settings - Fork 68
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
Update function objects section to the new format #648
base: main
Are you sure you want to change the base?
Conversation
Also fixes a bug in the return type of logical_and and logical_or.
In the WG meeting today we decided that we should define the return types of the |
Note that the decltype() only describes the return type of the operator, so it doesn't actually constrain the implementation of the operator.
- Add Precondition that T is Cpp17LessThanComparable. - Use the same wording for the Returns paragraph.
This should be read to review, now. Note that the Cpp17LessThanComparable requirement is a precondition and not a constraint. This was surprising to me, but I wanted to follow the ISO C++ definition: https://eel.is/c++draft/alg.min.max |
---- | ||
T operator()(const T& x, const T& y) const | ||
T operator()(const T& x, const T& y) const; |
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.
Good catch!
Not in the PR, but if you don't mind to a sneaky update (don't tell our editor :p ) :
This guy (4) is not aligned. |
---- | ||
T operator()(const T& x, const T& y) const | ||
template <class T, class U> constexpr auto operator()(T&& t, U&& u) const | ||
-> decltype(std::forward<T>(t) + std::forward<U>(u)); |
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.
Is there a motivation to have the std::forward
in the non-evaluated context?
Actually a maniac programmer could define +
with an l-reference to do division and a +
with an r-reference to do a multiplication?
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.
I don't know the motivation, but this is the way that the return type is declared for the equivalent function objects in in ISO C+ (e.g., https://eel.is/c++draft/function.objects#arithmetic.operations.plus-2).
I think you're right, though -- if std::forward<T>(t) + std::forward<U>(u)
is the statement that the operator will run, it's safer to include the std::forward
in the decltype
just in case somebody does something really weird.
Also fixes a bug in the return type of logical_and and logical_or. Closes #646.
The return types of the
void
specializations ofmaximum
andminimum
may require further discussion. Prior to this change, the specification didn't say exactly which operator(s) would be used to determine ordering, and so I tried to honor that in this new wording.When we introduced the prior wording there was some discussion of trying to align with
std::min
andstd::max
(see #285 (comment)). It we want to describe the behavior in terms of equivalent statements, I think the fix is to say:minimum
andmaximum
requireT
to beLessThanComparable
.minimum
returns(b < a) ? b : a
.maximum
returns(a < b) ? b : a
.