-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Avoid constraint recursion for expected<any, ...> and expected<void, any>
#4013
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f90311d
fix `expected<any,...>` and `expected<void,any>`
achabense e156420
add test
achabense 7c1ed3d
hide `_Not_self` and `_Allow_unwrapping`; simplify `friend swap(expec…
achabense 39f87ed
Casey's review comments
CaseyCarter 64b824e
Explicitly say `private:`.
StephanTLavavej File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -184,12 +184,28 @@ struct _Check_expected_argument : true_type { | |||||
|
|
||||||
| _EXPORT_STD template <class _Ty, class _Err> | ||||||
| class expected { | ||||||
| private: | ||||||
| static_assert(_Check_expected_argument<_Ty>::value); | ||||||
| static_assert(_Check_unexpected_argument<_Err>::value); | ||||||
|
|
||||||
| template <class _UTy, class _UErr> | ||||||
| friend class expected; | ||||||
|
|
||||||
| template <class _Uty, class _UErr> | ||||||
| static constexpr bool _Allow_unwrapping = disjunction_v<is_same<remove_cv_t<_Ty>, bool>, | ||||||
| negation<disjunction<is_constructible<_Ty, expected<_Uty, _UErr>&>, // | ||||||
| is_constructible<_Ty, expected<_Uty, _UErr>>, // | ||||||
| is_constructible<_Ty, const expected<_Uty, _UErr>&>, // | ||||||
| is_constructible<_Ty, const expected<_Uty, _UErr>>, // | ||||||
| is_convertible<expected<_Uty, _UErr>&, _Ty>, // | ||||||
| is_convertible<expected<_Uty, _UErr>&&, _Ty>, // | ||||||
| is_convertible<const expected<_Uty, _UErr>&, _Ty>, // | ||||||
| is_convertible<const expected<_Uty, _UErr>&&, _Ty>>>> // | ||||||
| && !is_constructible_v<unexpected<_Err>, expected<_Uty, _UErr>&> // | ||||||
| && !is_constructible_v<unexpected<_Err>, expected<_Uty, _UErr>> // | ||||||
| && !is_constructible_v<unexpected<_Err>, const expected<_Uty, _UErr>&> // | ||||||
| && !is_constructible_v<unexpected<_Err>, const expected<_Uty, _UErr>>; | ||||||
|
|
||||||
| public: | ||||||
| using value_type = _Ty; | ||||||
| using error_type = _Err; | ||||||
|
|
@@ -238,23 +254,8 @@ public: | |||||
| // clang-format on | ||||||
|
|
||||||
| template <class _Uty, class _UErr> | ||||||
| static constexpr bool _Allow_unwrapping = disjunction_v<is_same<remove_cv_t<_Ty>, bool>, | ||||||
| negation<disjunction<is_constructible<_Ty, expected<_Uty, _UErr>&>, // | ||||||
| is_constructible<_Ty, expected<_Uty, _UErr>>, // | ||||||
| is_constructible<_Ty, const expected<_Uty, _UErr>&>, // | ||||||
| is_constructible<_Ty, const expected<_Uty, _UErr>>, // | ||||||
| is_convertible<expected<_Uty, _UErr>&, _Ty>, // | ||||||
| is_convertible<expected<_Uty, _UErr>&&, _Ty>, // | ||||||
| is_convertible<const expected<_Uty, _UErr>&, _Ty>, // | ||||||
| is_convertible<const expected<_Uty, _UErr>&&, _Ty>>>> // | ||||||
| && !is_constructible_v<unexpected<_Err>, expected<_Uty, _UErr>&> // | ||||||
| && !is_constructible_v<unexpected<_Err>, expected<_Uty, _UErr>> // | ||||||
| && !is_constructible_v<unexpected<_Err>, const expected<_Uty, _UErr>&> // | ||||||
| && !is_constructible_v<unexpected<_Err>, const expected<_Uty, _UErr>>; | ||||||
|
Contributor
Author
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. Sorry for my untimely reply; if it's late to make new pushes and these changes look ok, I will carry these changes to another pr.
|
||||||
|
|
||||||
| template <class _Uty, class _UErr> | ||||||
| requires is_constructible_v<_Ty, const _Uty&> && is_constructible_v<_Err, const _UErr&> | ||||||
| && _Allow_unwrapping<_Uty, _UErr> | ||||||
| requires _Different_from<expected<_Uty, _UErr>, expected> && is_constructible_v<_Ty, const _Uty&> | ||||||
| && is_constructible_v<_Err, const _UErr&> && _Allow_unwrapping<_Uty, _UErr> | ||||||
| constexpr explicit(!is_convertible_v<const _Uty&, _Ty> || !is_convertible_v<const _UErr&, _Err>) | ||||||
| expected(const expected<_Uty, _UErr>& _Other) noexcept(is_nothrow_constructible_v<_Ty, const _Uty&> // | ||||||
| && is_nothrow_constructible_v<_Err, const _UErr&>) // strengthened | ||||||
|
|
@@ -267,7 +268,8 @@ public: | |||||
| } | ||||||
|
|
||||||
| template <class _Uty, class _UErr> | ||||||
| requires is_constructible_v<_Ty, _Uty> && is_constructible_v<_Err, _UErr> && _Allow_unwrapping<_Uty, _UErr> | ||||||
| requires _Different_from<expected<_Uty, _UErr>, expected> && is_constructible_v<_Ty, _Uty> | ||||||
| && is_constructible_v<_Err, _UErr> && _Allow_unwrapping<_Uty, _UErr> | ||||||
| constexpr explicit(!is_convertible_v<_Uty, _Ty> || !is_convertible_v<_UErr, _Err>) | ||||||
| expected(expected<_Uty, _UErr>&& _Other) noexcept( | ||||||
| is_nothrow_constructible_v<_Ty, _Uty>&& is_nothrow_constructible_v<_Err, _UErr>) // strengthened | ||||||
|
|
@@ -1161,11 +1163,18 @@ private: | |||||
| template <class _Ty, class _Err> | ||||||
| requires is_void_v<_Ty> | ||||||
| class expected<_Ty, _Err> { | ||||||
| private: | ||||||
| static_assert(_Check_unexpected_argument<_Err>::value); | ||||||
|
|
||||||
| template <class _UTy, class _UErr> | ||||||
| friend class expected; | ||||||
|
|
||||||
| template <class _Uty, class _UErr> | ||||||
| static constexpr bool _Allow_unwrapping = !is_constructible_v<unexpected<_Err>, expected<_Uty, _UErr>&> | ||||||
StephanTLavavej marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| && !is_constructible_v<unexpected<_Err>, expected<_Uty, _UErr>> | ||||||
| && !is_constructible_v<unexpected<_Err>, const expected<_Uty, _UErr>&> | ||||||
| && !is_constructible_v<unexpected<_Err>, const expected<_Uty, _UErr>>; | ||||||
|
|
||||||
| public: | ||||||
| using value_type = _Ty; | ||||||
| using error_type = _Err; | ||||||
|
|
@@ -1202,13 +1211,8 @@ public: | |||||
| // clang-format on | ||||||
|
|
||||||
| template <class _Uty, class _UErr> | ||||||
| static constexpr bool _Allow_unwrapping = !is_constructible_v<unexpected<_Err>, expected<_Uty, _UErr>&> | ||||||
| && !is_constructible_v<unexpected<_Err>, expected<_Uty, _UErr>> | ||||||
| && !is_constructible_v<unexpected<_Err>, const expected<_Uty, _UErr>&> | ||||||
| && !is_constructible_v<unexpected<_Err>, const expected<_Uty, _UErr>>; | ||||||
|
|
||||||
| template <class _Uty, class _UErr> | ||||||
| requires is_void_v<_Uty> && is_constructible_v<_Err, const _UErr&> && _Allow_unwrapping<_Uty, _UErr> | ||||||
| requires _Different_from<expected<_Uty, _UErr>, expected> && is_void_v<_Uty> | ||||||
| && is_constructible_v<_Err, const _UErr&> && _Allow_unwrapping<_Uty, _UErr> | ||||||
| constexpr explicit(!is_convertible_v<const _UErr&, _Err>) expected(const expected<_Uty, _UErr>& _Other) noexcept( | ||||||
| is_nothrow_constructible_v<_Err, const _UErr&>) // strengthened | ||||||
| : _Has_value(_Other._Has_value) { | ||||||
|
|
@@ -1218,7 +1222,8 @@ public: | |||||
| } | ||||||
|
|
||||||
| template <class _Uty, class _UErr> | ||||||
| requires is_void_v<_Uty> && is_constructible_v<_Err, _UErr> && _Allow_unwrapping<_Uty, _UErr> | ||||||
| requires _Different_from<expected<_Uty, _UErr>, expected> && is_void_v<_Uty> && is_constructible_v<_Err, _UErr> | ||||||
| && _Allow_unwrapping<_Uty, _UErr> | ||||||
| constexpr explicit(!is_convertible_v<_UErr, _Err>) | ||||||
| expected(expected<_Uty, _UErr>&& _Other) noexcept(is_nothrow_constructible_v<_Err, _UErr>) // strengthened | ||||||
| : _Has_value(_Other._Has_value) { | ||||||
|
|
@@ -1380,26 +1385,7 @@ public: | |||||
| is_nothrow_move_constructible_v<_Err>&& is_nothrow_swappable_v<_Err>) | ||||||
| requires is_swappable_v<_Err> && is_move_constructible_v<_Err> | ||||||
| { | ||||||
| using _STD swap; | ||||||
| if (_Left._Has_value && _Right._Has_value) { | ||||||
| // nothing | ||||||
| } else if (_Left._Has_value) { | ||||||
| _STD construct_at(_STD addressof(_Left._Unexpected), _STD move(_Right._Unexpected)); | ||||||
| if constexpr (!is_trivially_destructible_v<_Err>) { | ||||||
| _Right._Unexpected.~_Err(); | ||||||
| } | ||||||
| _Left._Has_value = false; | ||||||
| _Right._Has_value = true; | ||||||
| } else if (_Right._Has_value) { | ||||||
| _STD construct_at(_STD addressof(_Right._Unexpected), _STD move(_Left._Unexpected)); | ||||||
| if constexpr (!is_trivially_destructible_v<_Err>) { | ||||||
| _Left._Unexpected.~_Err(); | ||||||
| } | ||||||
| _Left._Has_value = true; | ||||||
| _Right._Has_value = false; | ||||||
| } else { | ||||||
| swap(_Left._Unexpected, _Right._Unexpected); // intentional ADL | ||||||
| } | ||||||
| _Left.swap(_Right); | ||||||
| } | ||||||
|
|
||||||
| // [expected.void.obs] | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.