[libcxx-commits] [libcxx] [libc++] Implement P2988R12: `std::optional<T&>` (PR #155202)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Thu Oct 30 22:47:48 PDT 2025


================
@@ -482,6 +474,16 @@ struct __optional_storage_base<_Tp, true> {
         __construct(std::forward<_That>(__opt).__get());
     }
   }
+
+  template <class _Up>
+  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __assign_from_val(_Up&& __val) {
+    __value_ = std::addressof(__val);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __swap(__optional_storage_base& __rhs) {
+    using std::swap;
+    swap(__value_, __rhs.__value_);
----------------
frederick-vs-ja wrote:

Ah. This is specified by the current standard wording - [[optional.ref.swap]/1](https://eel.is/c++draft/optional.ref.swap#1) that uses unqualified `swap`. But I think we should unconditionally use `std::swap`. I'm to submit an LWG issue.

https://github.com/llvm/llvm-project/pull/155202


More information about the libcxx-commits mailing list