-
Notifications
You must be signed in to change notification settings - Fork 1.6k
make _Get_unwrapped noexcept when possible #2991
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
Stephan T. Lavavej (StephanTLavavej)
merged 12 commits into
microsoft:main
from
strega-nil:is_nothrow_unwrapped
Aug 16, 2022
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
36fcea2
make _Get_unwrapped noexcept when possible
strega-nil 21962a4
fix build
strega-nil 10f2822
add _Unwrapped() && noexcept for path::iterator
strega-nil 3e9c474
add tests
strega-nil e53cbba
moar testing
strega-nil 8b48dc4
add more tests, use TRANSITION comments
strega-nil 349c061
review comments, make _Is_nothrow_unwrappable more normal
strega-nil 31bca24
switch to \implies to avoid extensions in test
strega-nil 8af9046
Casey's CRs
strega-nil c2ad1ea
ups
strega-nil 20e9994
Remove extraneous `()` of unknown origin
CaseyCarter 29faf88
STL CRs
strega-nil 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
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
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| RUNALL_INCLUDE ..\usual_matrix.lst |
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 |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #include <list> | ||
| #include <type_traits> | ||
| #include <vector> | ||
| #include <xutility> | ||
|
|
||
| #if _HAS_CXX17 | ||
| #include <filesystem> | ||
| #endif | ||
|
|
||
| #if _HAS_CXX20 | ||
| #include <ranges> | ||
| #endif | ||
|
|
||
| using namespace std; | ||
|
|
||
| #if _HAS_CXX17 | ||
| using filesystem::path; | ||
| #endif | ||
|
|
||
| #define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) | ||
|
|
||
| struct Predicate { | ||
| template <class T> | ||
| bool operator()(const T&) const { | ||
| return true; | ||
| } | ||
| }; | ||
|
|
||
| template <class It, bool CopyUnwrapNothrow = true> | ||
| void do_single_test() { | ||
| // !a || b is equivalent to a => b (a implies b) | ||
| // This is written this way to avoid `if constexpr` in C++14 mode. | ||
| STATIC_ASSERT(_Unwrappable_v<It> == _Is_nothrow_unwrappable_v<It>); | ||
| STATIC_ASSERT(_Unwrappable_v<It> == _Is_nothrow_unwrappable_v<It&&>); | ||
| STATIC_ASSERT(noexcept(_Get_unwrapped(declval<It>()))); | ||
|
|
||
| STATIC_ASSERT(!_Unwrappable_v<It> || _Is_nothrow_unwrappable_v<const It&> == CopyUnwrapNothrow); | ||
| STATIC_ASSERT(!_Unwrappable_v<It> || _Is_nothrow_unwrappable_v<const It&&> == CopyUnwrapNothrow); | ||
|
strega-nil-ms marked this conversation as resolved.
|
||
| STATIC_ASSERT(noexcept(_Get_unwrapped(declval<const It&>())) == CopyUnwrapNothrow); | ||
| STATIC_ASSERT(noexcept(_Get_unwrapped(declval<const It&&>())) == CopyUnwrapNothrow); | ||
| } | ||
|
|
||
| template <class It, bool CopyUnwrapNothrow = true> | ||
| void do_full_test() { | ||
| do_single_test<It, CopyUnwrapNothrow>(); | ||
| do_single_test<reverse_iterator<It>, CopyUnwrapNothrow>(); | ||
| do_single_test<move_iterator<It>, CopyUnwrapNothrow>(); | ||
|
|
||
| #ifdef __cpp_lib_concepts // TRANSITION, GH-395 | ||
| using R = ranges::subrange<It, It>; | ||
|
|
||
| // TRANSITION, GH-2997 | ||
| do_single_test<ranges::iterator_t<ranges::filter_view<R, Predicate>>, true>(); | ||
| // TRANSITION, GH-2997 | ||
| do_single_test<ranges::iterator_t<ranges::transform_view<R, Predicate>>, true>(); | ||
| if constexpr (bidirectional_iterator<It>) { | ||
| do_single_test<ranges::iterator_t<ranges::reverse_view<R>>, CopyUnwrapNothrow>(); | ||
| } | ||
| #endif // __cpp_lib_concepts | ||
| } | ||
|
|
||
| struct BidiIterUnwrapThrowing : vector<int>::iterator { | ||
|
strega-nil-ms marked this conversation as resolved.
|
||
| using Base = vector<int>::iterator; | ||
|
|
||
| using Base::Base; | ||
|
|
||
| using iterator_concept = bidirectional_iterator_tag; | ||
| using iterator_category = bidirectional_iterator_tag; | ||
|
|
||
| BidiIterUnwrapThrowing& operator++() { | ||
| Base::operator++(); | ||
| return *this; | ||
| } | ||
| BidiIterUnwrapThrowing operator++(int) { | ||
| auto res = *this; | ||
| Base::operator++(); | ||
| return res; | ||
| } | ||
| BidiIterUnwrapThrowing& operator--() { | ||
| Base::operator--(); | ||
| return *this; | ||
| } | ||
| BidiIterUnwrapThrowing operator--(int) { | ||
| auto res = *this; | ||
| Base::operator--(); | ||
| return res; | ||
| } | ||
|
|
||
| using _Prevent_inheriting_unwrap = BidiIterUnwrapThrowing; | ||
|
|
||
| int* _Unwrapped() const& noexcept(false) { | ||
| return Base::_Unwrapped(); | ||
| } | ||
| int* _Unwrapped() && noexcept { | ||
| return move(*this).Base::_Unwrapped(); | ||
| } | ||
|
|
||
| void _Seek_to(int* p) & noexcept { | ||
| Base::_Seek_to(p); | ||
| } | ||
| }; | ||
|
|
||
| int main() { | ||
| do_single_test<int>(); | ||
| do_full_test<int*>(); | ||
| do_single_test<int[]>(); | ||
|
|
||
| do_full_test<vector<int>::iterator>(); | ||
| do_full_test<vector<int>::const_iterator>(); | ||
| do_full_test<list<int>::iterator>(); | ||
| do_full_test<list<int>::const_iterator>(); | ||
|
|
||
| do_full_test<BidiIterUnwrapThrowing, false>(); | ||
| #if _HAS_CXX17 | ||
| do_full_test<path::iterator, false>(); | ||
| #endif | ||
| } | ||
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.