-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent calling make_optional<int&>(i) or make_optional<const int&>(i)
The status quo in C++23 is that int i; auto o = make_optional<int&>(i); produces an `optional<int>`, not an `optional<int&>`. This would be horribly confusing to propagate into C++26 — users would naturally expect to receive an `optional<int&>`. Worse, auto o = make_optional<int&>(std::ref(i)); actually *would* give you an `optional<int&>`, because it would use a different overload of `make_optional`! So, we propose to add a "Mandates" element to `make_optional` that requires its explicit template argument (if any) to be a non-array object type. This breaks the "status quo" example at the top of this comment (requiring an Annex C entry); but it successfully prevents the pitfalls. Thanks to Tomasz Kamiński for the template-programming trick, which matches the technique used in https://eel.is/c++draft/out.ptr .
- Loading branch information
1 parent
33b3dea
commit 4e115f1
Showing
4 changed files
with
25 additions
and
61 deletions.
There are no files selected for viewing
This file contains 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 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 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 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