5#ifndef INCLUDE_CPPGC_TAGGED_MEMBER_H_
6#define INCLUDE_CPPGC_TAGGED_MEMBER_H_
30template <
typename Po
intee,
typename Tag1,
typename Tag2>
35 "The tag must live in the alignment bits of the pointer.");
40 : ptr_(reinterpret_cast<Pointee*>(reinterpret_cast<uintptr_t>(ptr) |
43 template <
typename Tag>
45 auto* raw = ptr_.Get();
46 if constexpr (std::same_as<Tag, Tag1>) {
50 static_assert(std::same_as<Tag, Tag2>);
56 template <
typename Tag>
58 auto* raw = ptr_.Get();
59 if constexpr (std::same_as<Tag, Tag1>) {
60 return (
reinterpret_cast<uintptr_t
>(raw) &
kTagBit) ?
nullptr : raw;
62 static_assert(std::same_as<Tag, Tag2>);
63 return (
reinterpret_cast<uintptr_t
>(raw) &
kTagBit)
64 ?
reinterpret_cast<Pointee*
>(
reinterpret_cast<uintptr_t
>(raw) &
71 return reinterpret_cast<Pointee*
>(
reinterpret_cast<uintptr_t
>(ptr_.Get()) &
75 template <
typename Tag>
77 if constexpr (std::same_as<Tag, Tag1>) {
80 static_assert(std::same_as<Tag, Tag2>);
81 ptr_ =
reinterpret_cast<Pointee*
>(
reinterpret_cast<uintptr_t
>(pointee) |
86 template <
typename Tag>
88 const bool tag_set =
reinterpret_cast<uintptr_t
>(ptr_.Get()) &
kTagBit;
89 if constexpr (std::same_as<Tag, Tag1>) {
92 static_assert(std::same_as<Tag, Tag2>);
101 auto* untagged =
reinterpret_cast<Pointee*
>(
102 reinterpret_cast<uintptr_t
>(ptr_.GetRawAtomic()) & ~
kTagBit);
void Trace(const Member< T > &member)
Definition: visitor.h:93
Definition: tagged-member.h:31
Pointee * GetUntagged() const
Definition: tagged-member.h:70
Pointee * GetAs() const
Definition: tagged-member.h:44
void Trace(Visitor *v) const
Definition: tagged-member.h:97
TaggedUncompressedMember(Tag2, Pointee *ptr)
Definition: tagged-member.h:39
bool Is() const
Definition: tagged-member.h:87
void SetAs(Pointee *pointee)
Definition: tagged-member.h:76
static constexpr uintptr_t kTagBit
Definition: tagged-member.h:33
TaggedUncompressedMember(Tag1, Pointee *ptr)
Definition: tagged-member.h:38
Pointee * TryGetAs() const
Definition: tagged-member.h:57
#define CPPGC_DCHECK(condition)
Definition: logging.h:36
#define CPPGC_PLUGIN_IGNORE(bug_or_reason)
Definition: macros.h:46
#define CPPGC_DISALLOW_NEW()
Definition: macros.h:14
constexpr size_t kAllocationGranularity
Definition: api-constants.h:65
Definition: cross-thread-persistent.h:431