[libcxx-commits] [libcxx] [libc++] Add tombstone traits and use them in optional (PR #98498)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Dec 2 07:02:41 PST 2024


================
@@ -120,7 +123,13 @@ class _LIBCPP_TEMPLATE_VIS reference_wrapper : public __weak_result_type<_Tp> {
 #if _LIBCPP_STD_VER >= 17
 template <class _Tp>
 reference_wrapper(_Tp&) -> reference_wrapper<_Tp>;
-#endif
+
+template <class _Tp>
+struct __tombstone_traits<reference_wrapper<_Tp>> {
+  static constexpr uintptr_t __disengaged_value_  = __builtin_offsetof(reference_wrapper<_Tp>, __f_);
----------------
ldionne wrote:

IMO it would be more straightforward to use:

```
static constexpr _Tp* __disengaged_value_ = nullptr;
static constexpr size_t __is_disengaged_offset_ = __builtin_offsetof(reference_wrapper<_Tp>, __f_);
```

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


More information about the libcxx-commits mailing list