mirrored from git://gcc.gnu.org/git/gcc.git
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libstdc++: Implement monadic operations for std::optional (P0798R8)
Another new addition to the C++23 working draft. The new member functions of std::optional are only defined for C++23, but the new members of _Optional_payload_base are defined for C++20 so that they can be used in non-propagating-cache in <ranges>. The _Optional_payload_base::_M_construct member can also be used in non-propagating-cache now, because it's constexpr since r12-4389. There will be an LWG issue about the feature test macro, suggesting that we should just bump the value of __cpp_lib_optional instead. I haven't done that here, but it can be changed once consensus is reached on the change. libstdc++-v3/ChangeLog: * include/std/optional (_Optional_payload_base::_Storage): Add constructor taking a callable function to invoke. (_Optional_payload_base::_M_apply): New function. (__cpp_lib_monadic_optional): Define for C++23. (optional::and_then, optional::transform, optional::or_else): Define for C++23. * include/std/ranges (__detail::__cached): Remove. (__detail::__non_propagating_cache): Remove use of __cached for contained value. Use _Optional_payload_base::_M_construct and _Optional_payload_base::_M_apply to set the contained value. * include/std/version (__cpp_lib_monadic_optional): Define. * testsuite/20_util/optional/monadic/and_then.cc: New test. * testsuite/20_util/optional/monadic/or_else.cc: New test. * testsuite/20_util/optional/monadic/or_else_neg.cc: New test. * testsuite/20_util/optional/monadic/transform.cc: New test. * testsuite/20_util/optional/monadic/version.cc: New test.
- Loading branch information
Showing
8 changed files
with
573 additions
and
40 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
Oops, something went wrong.