You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Missing reversed params comparison ops for C++17 #9
C++17 needs additional comparison operator overloads with reversed parameters. For C++20 and newer it is unnecessary due to "synthesized three-way comparison" feature.
Equality is not all of the comparison. To acheive equality, we need only two functions, the operator== and operator!=, but six (plus operator<, operator>, operator<= and operator>=) for comparison.
You are missing the point, I am talking here about support for C++17, and to achieve (non-)equality we need in 12 overloads in total.
These are defined in spec (for non-void T):
operator==(expected, expected<T2, E2>)
operator==(expected, T2)
operator==(expected, unexpected)
So for C++17 you need additionally following:
reversed param order:
operator==(expected<T2, E2>, expected)
operator==(T2, expected)
operator==(unexpected, expected)
Activity
X1aomu commentedon Sep 18, 2024
The comparison operators of
expectedhave not yet be adopt in STL,, refered in P0323R12 .To avoid the possibly incompatible behaviour with STL, it's not perferred to implement this feature right now.
Free free to tell me if someday it comes :)
mcencora commentedon Nov 5, 2024
I don't understand. The comparison ops for std::expected are available since the beginning, see:
https://wg21.link/std23
Chapter:
22.8.6.8 Equality operators
X1aomu commentedon Nov 7, 2024
Hi, @mcencora
Equality is not all of the comparison. To acheive equality, we need only two functions, the
operator==andoperator!=, but six (plusoperator<,operator>,operator<=andoperator>=) for comparison.As what you post,
it only define three overloads of
operator==. So this is the thing of equality, andzeus::expectedhas reached that.mcencora commentedon Nov 7, 2024
You are missing the point, I am talking here about support for C++17, and to achieve (non-)equality we need in 12 overloads in total.
These are defined in spec (for non-void T):
operator==(expected, expected<T2, E2>)
operator==(expected, T2)
operator==(expected, unexpected)
So for C++17 you need additionally following:
reversed param order:
operator==(expected<T2, E2>, expected)
operator==(T2, expected)
operator==(unexpected, expected)
not-equal:
operator!=(expected, expected<T2, E2>)
operator!=(expected, T2)
operator!=(expected, unexpected)
not-equal reversed param order:
operator!=(expected<T2, E2>, expected)
operator!=(T2, expected)
operator!=(unexpected, expected)
X1aomu commentedon Nov 8, 2024
Ahh, I think I get the point now. Let me invastigate the scenario of reversed operands later.
Good catch!!!