-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[libc++] P3168R2 Give std::optional Range Support #146491
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
Closed
Closed
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
4b9c76b
[libcxx] add ranges::enable_view<optional<_T>> = true and format_kind…
dywoq ebda4e4
[libcxx] add forward declaration of __optional_iterator in <optional>
dywoq 6e97c34
[libcxx] add __optional_iterator
dywoq ef52562
[libcxxx] add begin() and end() to std::optional class
dywoq 820d96c
[libcxx] update includes in <optional> header
dywoq 5fc696b
[libcxx] add comment
dywoq 162170c
[libcxx] remove unimplemented: True parameter in generate_feature_tes…
dywoq f968252
[libcxx] update <version> header
dywoq 06109ed
[libcxx] write optional.range tests
dywoq fc75fe0
[libcxx] add optional.range.runtime_error.fail test
dywoq f939528
[libcxx] remove unused include
dywoq fdc917b
[libcxx] change path to assert_macros.h
dywoq e704aba
[libcxx] remove .clangd
dywoq f294f98
[libcxx] rename test
dywoq a720391
[libcxx] change iterator_category to random_access_iterator_tag <opti…
dywoq 4bfc9bb
[libcxx] remove operator!= for __optional_iterator in <optional>
dywoq 26974eb
[libcxx] add constexpr to __optional_iterator, optional<T>::begin and…
dywoq b61f90b
[libcxx] use assert in optional.range.iteration.pass test
dywoq 6993061
[libcxx] use static_assert in optional.range.satisfies_range_concept.…
dywoq a3ef155
[libcxx] add additional operators to __optional_iterator
dywoq 6d4be21
[libcxx] remove .clangd
dywoq 47ba868
[libcxx] add iterator_types.verify test to optional.ranges
dywoq 3f69eda
[libcxx] add missing new character line at EOF
dywoq ef8af0a
[libcxx] change optional.range.iteration.pass test to constant eveluated
dywoq 04b5511
[libcxx] use __wrap_iter in __optional_iterator
dywoq 3f6f457
[libcxx] add missing comment
dywoq 132bc39
[libcxx] add tests enable_ranges_view.pass and format_kind.pass in op…
dywoq 8c4d4df
[libcxx] remove .clangd
dywoq ef032f1
[libcxx] add friend declarations for __wrap_iter in __optional_iterator
dywoq 149ff9e
[libcxx] update const_iterator type to use const reference in optional
dywoq 0510945
[libcxx] simplify __optional_iterator operations and add to_address u…
dywoq 5be2e9d
[libcxx] rename enable_ranges_view.pass.cpp to enable_ranges_view.com…
dywoq e34c3bc
[libcxx] rename optional.range tests
dywoq fc0219e
[libcxx] remove main function blocks in optional.range.*.compile.pass…
dywoq b0393d6
[libcxx] update satisfies_range_concept test to include sized_range, …
dywoq d66ea58
[libcxx] remove __optional_iterator class
dywoq 42de74b
[libcxx] refactor iterator type assertions in optional.range
dywoq 99fb189
[libcxx] use test() along with static_assert(test()) in optional.rang…
dywoq 02cd53f
[libcxx] correct iterator type to use pointer types in optional
dywoq 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
17 changes: 17 additions & 0 deletions
17
libcxx/test/std/utilities/optional/optional.range/enable_ranges_view.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,17 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // UNSUPPORTED: std-at-least-c++26 | ||
|
|
||
| #include <optional> | ||
| #include <ranges> | ||
|
|
||
| int main() { | ||
| static_assert(std::ranges::enable_view<std::optional<int>>); | ||
| return 0; | ||
| } |
14 changes: 14 additions & 0 deletions
14
libcxx/test/std/utilities/optional/optional.range/format_kind.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,14 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // UNSUPPORTED: std-at-least-c++26 | ||
|
|
||
| #include <format> | ||
| #include <optional> | ||
|
|
||
| static_assert(std::format_kind<std::optional<int>>); |
26 changes: 26 additions & 0 deletions
26
libcxx/test/std/utilities/optional/optional.range/iteration.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,26 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
|
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. Please add comments in all tests what they are supported to do. |
||
| // UNSUPPORTED: std-at-least-c++26 | ||
|
|
||
| #include <cassert> | ||
| #include <optional> | ||
|
|
||
| constexpr bool test() { | ||
| constexpr std::optional<int> val = 2; | ||
| for (const auto& elem : val) | ||
| if (elem != 2) | ||
| return false; | ||
| return true; | ||
| } | ||
|
|
||
| int main() { | ||
| test(); | ||
| static_assert(test()); | ||
dywoq marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return 0; | ||
| } | ||
37 changes: 37 additions & 0 deletions
37
libcxx/test/std/utilities/optional/optional.range/iterator_types.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,37 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // UNSUPPORTED: std-at-least-c++26 | ||
|
|
||
| #include <iterator> | ||
| #include <type_traits> | ||
| #include <cstddef> | ||
| #include <optional> | ||
|
|
||
| using iterator = std::optional<int>::iterator; | ||
| using const_iterator = std::optional<int>::const_iterator; | ||
|
|
||
| // iterator | ||
|
|
||
| static_assert(std::random_access_iterator<iterator>); | ||
| static_assert(std::contiguous_iterator<iterator>); | ||
| static_assert(std::is_same_v<typename std::iterator_traits<iterator>::value_type, int>); | ||
| static_assert(std::is_same_v<typename std::iterator_traits<iterator>::difference_type, std::ptrdiff_t>); | ||
| static_assert(std::is_same_v<typename std::iterator_traits<iterator>::pointer, int*>); | ||
| static_assert(std::is_same_v<typename std::iterator_traits<iterator>::reference, int&>); | ||
| static_assert(std::is_same_v<typename std::iterator_traits<iterator>::iterator_category, std::random_access_iterator_tag>); | ||
|
|
||
| // const iterator | ||
|
|
||
| static_assert(std::random_access_iterator<const_iterator>); | ||
| static_assert(std::contiguous_iterator<const_iterator>); | ||
| static_assert(std::is_same_v<typename std::iterator_traits<const_iterator>::value_type, int>); | ||
| static_assert(std::is_same_v<typename std::iterator_traits<const_iterator>::difference_type, std::ptrdiff_t>); | ||
| static_assert(std::is_same_v<typename std::iterator_traits<const_iterator>::pointer, int*>); | ||
| static_assert(std::is_same_v<typename std::iterator_traits<const_iterator>::reference, int&>); | ||
| static_assert(std::is_same_v<typename std::iterator_traits<const_iterator>::iterator_category, std::random_access_iterator_tag>); |
19 changes: 19 additions & 0 deletions
19
libcxx/test/std/utilities/optional/optional.range/runtime_error.verify.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,19 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // UNSUPPORTED: std-at-least-c++26 | ||
|
|
||
| #include "assert_macros.h" | ||
| #include <optional> | ||
|
|
||
| int main() { | ||
| std::optional<int> val = 2; | ||
| auto end = val.end(); | ||
| TEST_DOES_NOT_THROW(*end); | ||
| return 0; | ||
| } |
16 changes: 16 additions & 0 deletions
16
libcxx/test/std/utilities/optional/optional.range/satisfies_range_concept.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,16 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // UNSUPPORTED: std-at-least-c++26 | ||
|
|
||
| #include <optional> | ||
| #include <ranges> | ||
|
|
||
| static_assert(std::ranges::sized_range<std::optional<int>>); | ||
| static_assert(std::ranges::common_range<std::optional<int>>); | ||
| static_assert(std::ranges::contiguous_range<std::optional<int>>); |
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.
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.
These don't have tests AFAICT.