[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:40 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_);
+ static constexpr size_t __is_disengaged_offset_ = 0;
----------------
ldionne wrote:
As you noticed during live review, these are reversed. This needs a test that would at least fail if we changed the offsetof value. In fact, I'd like a basic test with `optional<T>` for every `T` that we give `tombstone_traits` to, just to make sure that basic stuff works.
https://github.com/llvm/llvm-project/pull/98498
More information about the libcxx-commits
mailing list