-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[libc++] Implement P3168R2: Give optional range support #149441
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
28 commits
Select commit
Hold shift + click to select a range
8ded270
Implement P2988R12: Give optional range support
smallp-o-p bb40f19
Misinputted columns in Cxx2cPapers.csv
smallp-o-p 7091f79
Address most comments
smallp-o-p 0cb1e28
Clang-Format :^)
smallp-o-p 72feef4
Mostly revert conditional inclusion change (for now) due to a circula…
smallp-o-p f4d2248
Remove mentions of implementation in Libc++ 21, should go to Libc++ 2…
smallp-o-p 7923bd7
Add entry to libc++ 22 release notes
smallp-o-p 2b7255c
implicit bool conversions are evil
smallp-o-p a88b331
Split test file into three tests
smallp-o-p 700d95e
Remove usage of remove_cvref_t for pointer and const pointer types si…
smallp-o-p df5413f
Fix a comment, forgot a noexcept test
smallp-o-p 0e01b3a
Copy mistake
smallp-o-p c6459b5
Add hardening with bounded_iter
smallp-o-p 9d044a3
Fix misplaced parens
smallp-o-p 1a0b532
Remove some transitive includes that were removed with #150583
smallp-o-p 34f7766
Remove include guard since it's no longer necessary
smallp-o-p 8005225
Address comments
smallp-o-p 80be924
Forgot to rename a variable
smallp-o-p 0c6ba2f
Use std::as_const pattern for all tests
smallp-o-p d44913e
Rename pointer type and unguard it
smallp-o-p 1c9c978
Disallow T(&)[] and T&(Args...) from having iterator types as pre-cau…
smallp-o-p 8c25875
Forgot an #include
smallp-o-p 169cd4e
Retrigger Build
smallp-o-p 676fe45
is_unbounded_array is >= C++20
smallp-o-p 15f0d61
Bring in __pointer types too, there is probably a better way to do th…
smallp-o-p 5f01307
Remove unnecessary public:
smallp-o-p 86790ad
Don't worry about references
smallp-o-p 4827fa8
Update documentation
smallp-o-p 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
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
30 changes: 30 additions & 0 deletions
30
libcxx/test/libcxx/utilities/optional/optional.iterator/iterator.compile.pass.cpp
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,30 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// REQUIRES: std-at-least-c++26 | ||
|
||
// <optional> | ||
|
||
// template <class T> class optional::iterator; | ||
// template <class T> class optional::const_iterator; | ||
|
||
#include <optional> | ||
|
||
template <typename T> | ||
concept has_iterator_aliases = requires { | ||
typename T::iterator; | ||
typename T::const_iterator; | ||
}; | ||
|
||
static_assert(has_iterator_aliases<std::optional<int>>); | ||
static_assert(has_iterator_aliases<std::optional<const int>>); | ||
|
||
// TODO: Uncomment these once P2988R12 is implemented, as they would be testing optional<T&> | ||
|
||
// static_assert(!has_iterator_aliases<std::optional<int (&)[]>>); | ||
// static_assert(!has_iterator_aliases<std::optional<void (&)(int, char)>>); |
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
64 changes: 64 additions & 0 deletions
64
libcxx/test/std/utilities/optional/optional.iterator/begin.pass.cpp
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,64 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// REQUIRES: std-at-least-c++26 | ||
|
||
// <optional> | ||
|
||
// constexpr iterator optional::begin() noexcept; | ||
// constexpr const_iterator optional::begin() const noexcept; | ||
|
||
#include <cassert> | ||
#include <iterator> | ||
#include <optional> | ||
#include <type_traits> | ||
#include <utility> | ||
|
||
template <typename T> | ||
constexpr bool test() { | ||
std::optional<T> opt{T{}}; | ||
|
||
{ // begin() is marked noexcept | ||
static_assert(noexcept(opt.begin())); | ||
static_assert(noexcept(std::as_const(opt).begin())); | ||
} | ||
|
||
{ // Dereferencing an iterator at the beginning == indexing the 0th element, and that calling begin() again return the same iterator. | ||
auto iter1 = opt.begin(); | ||
auto iter2 = std::as_const(opt).begin(); | ||
assert(*iter1 == iter1[0]); | ||
assert(*iter2 == iter2[0]); | ||
assert(iter1 == opt.begin()); | ||
assert(iter2 == std::as_const(opt).begin()); | ||
} | ||
|
||
{ // Calling begin() multiple times on a disengaged optional returns the same iterator. | ||
std::optional<T> disengaged{std::nullopt}; | ||
auto iter1 = disengaged.begin(); | ||
auto iter2 = std::as_const(disengaged).begin(); | ||
assert(iter1 == disengaged.begin()); | ||
assert(iter2 == std::as_const(disengaged).begin()); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
constexpr bool tests() { | ||
assert(test<int>()); | ||
assert(test<char>()); | ||
assert(test<const int>()); | ||
assert(test<const char>()); | ||
return true; | ||
} | ||
|
||
int main(int, char**) { | ||
assert(tests()); | ||
static_assert(tests()); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.