5#ifndef INCLUDE_CPPGC_TAGGED_MEMBER_H_
6#define INCLUDE_CPPGC_TAGGED_MEMBER_H_
13#include "cppgc/internal/api-constants.h"
14#include "cppgc/macros.h"
15#include "cppgc/member.h"
16#include "cppgc/visitor.h"
31template <
typename Pointee,
typename Tag1,
typename Tag2>
34 static constexpr uintptr_t kTagBit = 0b1;
36 "The tag must live in the alignment bits of the pointer.");
44 template <
typename Tag>
46 auto* raw = ptr_.Get();
47 if constexpr (std::same_as<Tag, Tag1>) {
51 static_assert(std::same_as<Tag, Tag2>);
57 template <
typename Tag>
59 auto* raw = ptr_.Get();
60 if constexpr (std::same_as<Tag, Tag1>) {
61 return (
reinterpret_cast<uintptr_t>(raw) & kTagBit) ?
nullptr : raw;
63 static_assert(std::same_as<Tag, Tag2>);
64 return (
reinterpret_cast<uintptr_t>(raw) & kTagBit)
65 ?
reinterpret_cast<Pointee*>(
reinterpret_cast<uintptr_t>(raw) &
72 return reinterpret_cast<Pointee*>(
reinterpret_cast<uintptr_t>(ptr_.Get()) &
76 template <
typename Tag>
78 if constexpr (std::same_as<Tag, Tag1>) {
81 static_assert(std::same_as<Tag, Tag2>);
82 ptr_ =
reinterpret_cast<Pointee*>(
reinterpret_cast<uintptr_t>(pointee) |
87 template <
typename Tag>
89 const bool tag_set =
reinterpret_cast<uintptr_t>(ptr_.Get()) & kTagBit;
90 if constexpr (std::same_as<Tag, Tag1>) {
93 static_assert(std::same_as<Tag, Tag2>);
102 auto* untagged =
reinterpret_cast<Pointee*>(
103 reinterpret_cast<uintptr_t>(ptr_.GetRawAtomic()) & ~kTagBit);
104 UncompressedMember<Pointee> temp(untagged);
friend class cppgc::subtle::TaggedUncompressedMember
void SetAs(Pointee *pointee)
TaggedUncompressedMember(Tag1, Pointee *ptr)
TaggedUncompressedMember(Tag2, Pointee *ptr)
Pointee * TryGetAs() const
Pointee * GetUntagged() const
void Trace(Visitor *v) const
#define CPPGC_DCHECK(condition)
#define CPPGC_PLUGIN_IGNORE(bug_or_reason)
#define CPPGC_DISALLOW_NEW()
constexpr size_t kAllocationGranularity