-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libc++] Implement P2988R12: std::optional<T&>
#155202
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 27 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
72bb6e9
Augment tests
smallp-o-p df2e9e7
formatting
smallp-o-p 322079d
Forgot to gate a test
smallp-o-p 2a014d8
Update generated files
smallp-o-p 294cb8e
Formatting
smallp-o-p 762bb8c
Update documentation
smallp-o-p 223ce49
Update optional to allow T&, disable iterator and value_or for T(&)()
smallp-o-p 92137cb
Remove nullptr dereference in iterator
smallp-o-p c123551
Left in an extraneous paren
smallp-o-p 9075442
Python formatting
smallp-o-p 0ca1d51
Fix merge oops
smallp-o-p 4ba0c8f
Formatting and include
smallp-o-p 660716c
Gate ref tests, use std::same_as suggestion
smallp-o-p 717c5f9
Fix GCC shadow warning
smallp-o-p 1612378
Add constraint to emplace, add deleted optional<T&> constructors, add…
smallp-o-p ea6ce10
Remove __can_bind_reference() in favor of __reference_constructs_from…
smallp-o-p 089cb71
Assignment shouldn't modify the underlying value, test for that and a…
smallp-o-p c602898
Clang-Format
smallp-o-p 42637ff
Address comments + Add some tests for function refs and array refs
smallp-o-p 3c9c51b
Change a few more static_asserts
smallp-o-p dfb3349
Fix up swap, make_optional, add tests
smallp-o-p bc68310
Address nits
smallp-o-p 4f87438
Formatting
smallp-o-p e586acd
Formatting x2
smallp-o-p 18c1b96
Fix typo
smallp-o-p 1add5c5
Allow make_optional for T&, add test
smallp-o-p 85db654
Formatting
smallp-o-p 65e92c4
Use std::swap, mark T& assignment and __swap noexcept
smallp-o-p 5cf4603
Replace all usages of optional::value_type with _Tp, remove reference…
smallp-o-p 3c2473d
Clean up deleted constructors signatures
smallp-o-p 4f58bf2
Drive-by: Add a ranges::range<optional<T>> test for iterators
smallp-o-p ba998d7
Add enable_borrowed_range<optional<T&>> and corresponding test
smallp-o-p 44d8d05
Add to module inc
smallp-o-p 1cd8ebe
Make the borrowed_range test compile only
smallp-o-p d32557c
Remove std:: prefixes in iterator struct
smallp-o-p 2d327fd
Simplify borrowed_range test
smallp-o-p 880558a
ditto
smallp-o-p 995bb75
ADL lookup
smallp-o-p cddffc5
ADL lookup
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
28 changes: 28 additions & 0 deletions
28
...bcxx/utilities/optional/optional.object/optional.object.observe/value_or.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,28 @@ | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 U> T optional<T>::value_or(U&&); | ||
|
|
||
| #include <concepts> | ||
| #include <optional> | ||
|
|
||
| template <typename Opt, typename T> | ||
| concept has_value_or = requires(Opt opt, T&& t) { | ||
| { opt.value_or(t) } -> std::same_as<T>; | ||
| }; | ||
|
|
||
| static_assert(has_value_or<std::optional<int>, int>); | ||
| static_assert(has_value_or<std::optional<int&>, int&>); | ||
| static_assert(has_value_or<std::optional<const int&>, const int&>); | ||
| static_assert(!has_value_or<std::optional<int (&)[1]>&&, int (&)[1]>); | ||
| static_assert(!has_value_or<std::optional<int (&)()>&&, 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
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 |
|---|---|---|
|
|
@@ -21,7 +21,8 @@ | |
|
|
||
| template <typename T> | ||
| constexpr bool test() { | ||
| std::optional<T> opt{T{}}; | ||
| std::remove_reference_t<T> t = std::remove_reference_t<T>{}; | ||
| std::optional<T> opt{t}; | ||
|
|
||
| { // begin() is marked noexcept | ||
| static_assert(noexcept(opt.begin())); | ||
|
|
@@ -53,6 +54,10 @@ constexpr bool tests() { | |
| assert(test<char>()); | ||
| assert(test<const int>()); | ||
| assert(test<const char>()); | ||
| assert(test<int&>()); | ||
| assert(test<char&>()); | ||
| assert(test<const int&>()); | ||
| assert(test<const char&>()); | ||
|
Contributor
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. Ditto, if you think it's better not to delay implementing LWG4308, cases for |
||
| return true; | ||
| } | ||
|
|
||
|
|
||
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
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.
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.
Looks like that we should achieve the following results, per the current resolution of LWG4308.
The product code needs to be correspondingly adjusted. We can do this in a following-up PR as LWG4308 is not formally accepted yet (but it will be soon).