-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[libc++] P3379R1: Constrain std::expected
equality operators
#117664
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
Changes from all commits
002fcac
408b331
6d540b6
02d1d91
805ac6a
437dec5
307559f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
#define _LIBCPP___EXPECTED_EXPECTED_H | ||
|
||
#include <__assert> | ||
#include <__concepts/convertible_to.h> | ||
#include <__config> | ||
#include <__expected/bad_expected_access.h> | ||
#include <__expected/unexpect.h> | ||
|
@@ -1139,7 +1140,15 @@ class expected : private __expected_base<_Tp, _Err> { | |
|
||
// [expected.object.eq], equality operators | ||
template <class _T2, class _E2> | ||
# if _LIBCPP_STD_VER >= 26 | ||
requires(!is_void_v<_T2> && | ||
requires(const _Tp& __tp, const _T2& __t2, const _Err& __err, const _E2& __e2) { | ||
{ __tp == __t2 } -> convertible_to<bool>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we can have the following. Internal concept
|
||
{ __err == __e2 } -> convertible_to<bool>; | ||
}) | ||
# else | ||
requires(!is_void_v<_T2>) | ||
# endif | ||
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const expected<_T2, _E2>& __y) { | ||
if (__x.__has_val() != __y.__has_val()) { | ||
return false; | ||
|
@@ -1153,11 +1162,22 @@ class expected : private __expected_base<_Tp, _Err> { | |
} | ||
|
||
template <class _T2> | ||
# if _LIBCPP_STD_VER >= 26 | ||
requires(!__is_std_expected<_T2>::value && | ||
requires(const _Tp& __tp, const _T2& __t2) { | ||
{ __tp == __t2 } -> convertible_to<bool>; | ||
}) | ||
# endif | ||
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const _T2& __v) { | ||
return __x.__has_val() && static_cast<bool>(__x.__val() == __v); | ||
} | ||
|
||
template <class _E2> | ||
# if _LIBCPP_STD_VER >= 26 | ||
requires requires(const _Err& __err, const _E2& __e2) { | ||
{ __err == __e2 } -> convertible_to<bool>; | ||
} | ||
# endif | ||
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const unexpected<_E2>& __e) { | ||
return !__x.__has_val() && static_cast<bool>(__x.__unex() == __e.error()); | ||
} | ||
|
@@ -1850,7 +1870,14 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { | |
|
||
// [expected.void.eq], equality operators | ||
template <class _T2, class _E2> | ||
# if _LIBCPP_STD_VER >= 26 | ||
requires(is_void_v<_T2> && | ||
requires(const _Err& __err, const _E2& __e2) { | ||
{ __err == __e2 } -> convertible_to<bool>; | ||
}) | ||
# else | ||
requires is_void_v<_T2> | ||
# endif | ||
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const expected<_T2, _E2>& __y) { | ||
if (__x.__has_val() != __y.__has_val()) { | ||
return false; | ||
|
@@ -1860,6 +1887,11 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { | |
} | ||
|
||
template <class _E2> | ||
# if _LIBCPP_STD_VER >= 26 | ||
requires requires(const _Err& __err, const _E2& __e2) { | ||
{ __err == __e2 } -> convertible_to<bool>; | ||
} | ||
# endif | ||
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const unexpected<_E2>& __y) { | ||
return !__x.__has_val() && static_cast<bool>(__x.__unex() == __y.error()); | ||
} | ||
|
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.
The paper number is R0, please adjust all references in the PR
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.
There was a D3379R1 draft but I forgot to publish it, and we voted on R0. The only difference is that R1 said to add
__cpp_lib_constrained_equality
in<expected>
. That addition got done editorially: cplusplus/draft#7449It looks like this PR neither bumps the macro value nor adds the macro to
<expected>
.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've submitted brevzin/sd6#28 to update SD-6.