diff options
author | swarmer <[email protected]> | 2025-06-11 21:26:47 +0300 |
---|---|---|
committer | swarmer <[email protected]> | 2025-06-11 21:45:25 +0300 |
commit | 3575c304717964c7bd650dedfa74c8da773e5af4 (patch) | |
tree | a7b39b8911dca164a4ed69a318ac4a01dcc1670b | |
parent | 76cde1f9a068bc0c9dd7b76de0290db84c5926f1 (diff) |
Enable std::optional monadic operations
Make monadic methods usable without switching to the C++23.
commit_hash:3690a8da41d8ed8aac44bc0f7d238c076eb1e603
4 files changed, 107 insertions, 10 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/include/optional b/contrib/libs/cxxsupp/libcxx/include/optional index f7224a2e036..f5c46aa0364 100644 --- a/contrib/libs/cxxsupp/libcxx/include/optional +++ b/contrib/libs/cxxsupp/libcxx/include/optional @@ -302,7 +302,7 @@ struct __optional_destruct_base<_Tp, false> { _LIBCPP_HIDE_FROM_ABI constexpr explicit __optional_destruct_base(in_place_t, _Args&&... __args) : __val_(std::forward<_Args>(__args)...), __engaged_(true) {} -# if _LIBCPP_STD_VER >= 23 +# if _LIBCPP_STD_VER >= 20 template <class _Fp, class... _Args> _LIBCPP_HIDE_FROM_ABI constexpr explicit __optional_destruct_base( __optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args) @@ -333,7 +333,7 @@ struct __optional_destruct_base<_Tp, true> { _LIBCPP_HIDE_FROM_ABI constexpr explicit __optional_destruct_base(in_place_t, _Args&&... __args) : __val_(std::forward<_Args>(__args)...), __engaged_(true) {} -# if _LIBCPP_STD_VER >= 23 +# if _LIBCPP_STD_VER >= 20 template <class _Fp, class... _Args> _LIBCPP_HIDE_FROM_ABI constexpr __optional_destruct_base( __optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args) @@ -709,7 +709,7 @@ public: this->__construct_from(std::move(__v)); } -# if _LIBCPP_STD_VER >= 23 +# if _LIBCPP_STD_VER >= 20 template <class _Tag, class _Fp, class... _Args, @@ -862,7 +862,7 @@ public: return this->has_value() ? std::move(this->__get()) : static_cast<value_type>(std::forward<_Up>(__v)); } -# if _LIBCPP_STD_VER >= 23 +# if _LIBCPP_STD_VER >= 20 template <class _Func> _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto and_then(_Func&& __f) & { using _Up = invoke_result_t<_Func, value_type&>; @@ -972,7 +972,7 @@ public: return std::move(*this); return std::forward<_Func>(__f)(); } -# endif // _LIBCPP_STD_VER >= 23 +# endif // _LIBCPP_STD_VER >= 20 using __base::reset; }; diff --git a/contrib/libs/cxxsupp/libcxx/patches/81-enable-std-optional-monadic.patch b/contrib/libs/cxxsupp/libcxx/patches/81-enable-std-optional-monadic.patch new file mode 100644 index 00000000000..d037ceb8703 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxx/patches/81-enable-std-optional-monadic.patch @@ -0,0 +1,49 @@ +diff --git a/include/optional b/include/optional +index f7224a2..f5c46aa 100644 +--- a/include/optional ++++ b/include/optional +@@ -302,7 +302,7 @@ struct __optional_destruct_base<_Tp, false> { + _LIBCPP_HIDE_FROM_ABI constexpr explicit __optional_destruct_base(in_place_t, _Args&&... __args) + : __val_(std::forward<_Args>(__args)...), __engaged_(true) {} + +-# if _LIBCPP_STD_VER >= 23 ++# if _LIBCPP_STD_VER >= 20 + template <class _Fp, class... _Args> + _LIBCPP_HIDE_FROM_ABI constexpr explicit __optional_destruct_base( + __optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args) +@@ -333,7 +333,7 @@ struct __optional_destruct_base<_Tp, true> { + _LIBCPP_HIDE_FROM_ABI constexpr explicit __optional_destruct_base(in_place_t, _Args&&... __args) + : __val_(std::forward<_Args>(__args)...), __engaged_(true) {} + +-# if _LIBCPP_STD_VER >= 23 ++# if _LIBCPP_STD_VER >= 20 + template <class _Fp, class... _Args> + _LIBCPP_HIDE_FROM_ABI constexpr __optional_destruct_base( + __optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args) +@@ -709,7 +709,7 @@ public: + this->__construct_from(std::move(__v)); + } + +-# if _LIBCPP_STD_VER >= 23 ++# if _LIBCPP_STD_VER >= 20 + template <class _Tag, + class _Fp, + class... _Args, +@@ -862,7 +862,7 @@ public: + return this->has_value() ? std::move(this->__get()) : static_cast<value_type>(std::forward<_Up>(__v)); + } + +-# if _LIBCPP_STD_VER >= 23 ++# if _LIBCPP_STD_VER >= 20 + template <class _Func> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto and_then(_Func&& __f) & { + using _Up = invoke_result_t<_Func, value_type&>; +@@ -972,7 +972,7 @@ public: + return std::move(*this); + return std::forward<_Func>(__f)(); + } +-# endif // _LIBCPP_STD_VER >= 23 ++# endif // _LIBCPP_STD_VER >= 20 + + using __base::reset; + }; diff --git a/contrib/libs/cxxsupp/libcxxcuda11/include/optional b/contrib/libs/cxxsupp/libcxxcuda11/include/optional index 4048fa2f59a..1f90edee1a8 100644 --- a/contrib/libs/cxxsupp/libcxxcuda11/include/optional +++ b/contrib/libs/cxxsupp/libcxxcuda11/include/optional @@ -318,7 +318,7 @@ struct __optional_destruct_base<_Tp, false> : __val_(_VSTD::forward<_Args>(__args)...), __engaged_(true) {} -#if _LIBCPP_STD_VER >= 23 +#if _LIBCPP_STD_VER >= 20 template <class _Fp, class... _Args> _LIBCPP_HIDE_FROM_ABI constexpr __optional_destruct_base(__optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args) @@ -360,7 +360,7 @@ struct __optional_destruct_base<_Tp, true> : __val_(_VSTD::forward<_Args>(__args)...), __engaged_(true) {} -#if _LIBCPP_STD_VER >= 23 +#if _LIBCPP_STD_VER >= 20 template <class _Fp, class... _Args> _LIBCPP_HIDE_FROM_ABI constexpr __optional_destruct_base(__optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args) @@ -873,7 +873,7 @@ public: this->__construct_from(_VSTD::move(__v)); } -#if _LIBCPP_STD_VER >= 23 +#if _LIBCPP_STD_VER >= 20 template<class _Fp, class... _Args> _LIBCPP_HIDE_FROM_ABI constexpr explicit optional(__optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args) @@ -1115,7 +1115,7 @@ public: static_cast<value_type>(_VSTD::forward<_Up>(__v)); } -#if _LIBCPP_STD_VER >= 23 +#if _LIBCPP_STD_VER >= 20 template<class _Func> _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto and_then(_Func&& __f) & { @@ -1239,7 +1239,7 @@ public: return _VSTD::move(*this); return _VSTD::forward<_Func>(__f)(); } -#endif // _LIBCPP_STD_VER >= 23 +#endif // _LIBCPP_STD_VER >= 20 using __base::reset; }; diff --git a/contrib/libs/cxxsupp/libcxxcuda11/patches/81-enable-std-optional-monadic.patch b/contrib/libs/cxxsupp/libcxxcuda11/patches/81-enable-std-optional-monadic.patch new file mode 100644 index 00000000000..4978a7dbc3e --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxcuda11/patches/81-enable-std-optional-monadic.patch @@ -0,0 +1,48 @@ +diff --git a/include/optional b/include/optional +--- a/include/optional ++++ b/include/optional +@@ -318,7 +318,7 @@ struct __optional_destruct_base<_Tp, false> + : __val_(_VSTD::forward<_Args>(__args)...), + __engaged_(true) {} + +-#if _LIBCPP_STD_VER >= 23 ++#if _LIBCPP_STD_VER >= 20 + template <class _Fp, class... _Args> + _LIBCPP_HIDE_FROM_ABI + constexpr __optional_destruct_base(__optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args) +@@ -360,7 +360,7 @@ struct __optional_destruct_base<_Tp, true> + : __val_(_VSTD::forward<_Args>(__args)...), + __engaged_(true) {} + +-#if _LIBCPP_STD_VER >= 23 ++#if _LIBCPP_STD_VER >= 20 + template <class _Fp, class... _Args> + _LIBCPP_HIDE_FROM_ABI + constexpr __optional_destruct_base(__optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args) +@@ -873,7 +873,7 @@ public: + this->__construct_from(_VSTD::move(__v)); + } + +-#if _LIBCPP_STD_VER >= 23 ++#if _LIBCPP_STD_VER >= 20 + template<class _Fp, class... _Args> + _LIBCPP_HIDE_FROM_ABI + constexpr explicit optional(__optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args) +@@ -1115,7 +1115,7 @@ public: + static_cast<value_type>(_VSTD::forward<_Up>(__v)); + } + +-#if _LIBCPP_STD_VER >= 23 ++#if _LIBCPP_STD_VER >= 20 + template<class _Func> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS + constexpr auto and_then(_Func&& __f) & { +@@ -1239,7 +1239,7 @@ public: + return _VSTD::move(*this); + return _VSTD::forward<_Func>(__f)(); + } +-#endif // _LIBCPP_STD_VER >= 23 ++#endif // _LIBCPP_STD_VER >= 20 + + using __base::reset; + }; |