[libcxx-commits] [libcxx] [libc++] Add tombstone traits to use in optional, variant (PR #98498)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jul 11 09:31:52 PDT 2024
================
@@ -0,0 +1,171 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___TYPE_TRAITS_DISENGAGED_TRAITS_H
+#define _LIBCPP___TYPE_TRAITS_DISENGAGED_TRAITS_H
+
+#include <__config>
+#include <__memory/construct_at.h>
+#include <__type_traits/datasizeof.h>
+#include <__type_traits/enable_if.h>
+#include <__type_traits/is_constant_evaluated.h>
+#include <__type_traits/is_fundamental.h>
+#include <__type_traits/is_trivially_destructible.h>
+#include <__type_traits/void_t.h>
+#include <__utility/forward_like.h>
+#include <__utility/in_place.h>
+#include <__utility/piecewise_construct.h>
+#include <__utility/pointer_int_pair.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class>
+struct __tombstone_memory_layout;
+
+// bools have always exactly one bit set. If there is more than one set it's disengaged.
+template <>
+struct __tombstone_memory_layout<bool> {
+ static constexpr uint8_t __disengaged_value_ = 3;
+ static constexpr size_t __is_disengaged_offset_ = 0;
+};
+
+struct __tombstone_pointer_layout {
----------------
ldionne wrote:
I'm not a fan of defining `__tombstone_pointer_layout` since there are unwritten assumptions you're making in that type (namely the alignment of the pointed-to type).
https://github.com/llvm/llvm-project/pull/98498
More information about the libcxx-commits
mailing list