15#ifndef WPIUTIL_WPI_POINTERUNION_H
16#define WPIUTIL_WPI_POINTERUNION_H
30template <
typename T,
typename... Us>
struct TypesAreDistinct;
31template <
typename T,
typename... Us>
33 : std::integral_constant<bool, !std::disjunction_v<std::is_same<T, Us>...> &&
34 TypesAreDistinct<Us...>::value> {};
47template <
typename... Ts>
49 : std::integral_constant<bool, detail::TypesAreDistinct<Ts...>::value> {};
62template <
typename T,
typename U,
typename... Us>
64 : std::integral_constant<size_t, 1 + FirstIndexOfType<T, Us...>::value> {};
65template <
typename T,
typename... Us>
71template <
size_t I,
typename... Ts>
72using TypeAtIndex = std::tuple_element_t<I, std::tuple<Ts...>>;
74namespace pointer_union_detail {
99 template <
typename Derived,
typename ValTy,
int I,
typename ...Types>
102 template <
typename Derived,
typename ValTy,
int I>
112 template <
typename Derived,
typename ValTy,
int I,
typename Type,
121 :
Base(ValTy(const_cast<void *>(
125 using Base::operator=;
130 return static_cast<Derived &
>(*this);
152template <
typename... PTs>
155 PointerUnion<PTs...>,
157 void *, pointer_union_detail::bitsRequired(sizeof...(PTs)), int,
158 pointer_union_detail::PointerUnionUIntTraits<PTs...>>,
161 "PointerUnion alternative types cannot be repeated");
168 using Base =
typename PointerUnion::PointerUnionMembers;
178 bool isNull()
const {
return !this->Val.getPointer(); }
180 explicit operator bool()
const {
return !
isNull(); }
183 template <
typename T>
bool is()
const {
190 template <
typename T> T
get()
const {
191 assert(is<T>() &&
"Invalid accessor called");
212 assert(is<First>() &&
"Val is not the first pointer");
215 this->Val.getPointer() &&
216 "Can't get the address because PointerLikeTypeTraits changes the ptr");
217 return const_cast<First *
>(
218 reinterpret_cast<const First *
>(this->Val.getAddrOfPointer()));
223 this->Val.initWithPointer(
nullptr);
228 using Base::operator=;
238template <
typename ...PTs>
243template <
typename ...PTs>
248template <
typename ...PTs>
255template <
typename ...PTs>
280 return Union(FirstInfo::getTombstoneKey());
This file defines DenseMapInfo traits for DenseMap.
This file defines the PointerIntPair class.
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Definition: PointerUnion.h:159
static PointerUnion getFromOpaqueValue(void *VP)
Definition: PointerUnion.h:231
T dyn_cast() const
Returns the current pointer if it is of the specified pointer type, otherwise returns null.
Definition: PointerUnion.h:197
void * getOpaqueValue() const
Definition: PointerUnion.h:230
First * getAddrOfPtr1()
If the union is set to the first pointer type get an address pointing to it.
Definition: PointerUnion.h:211
PointerUnion(std::nullptr_t)
Definition: PointerUnion.h:173
First const * getAddrOfPtr1() const
If the union is set to the first pointer type get an address pointing to it.
Definition: PointerUnion.h:205
const PointerUnion & operator=(std::nullptr_t)
Assignment from nullptr which just clears the union.
Definition: PointerUnion.h:222
T get() const
Returns the value of the specified pointer type.
Definition: PointerUnion.h:190
bool isNull() const
Test if the pointer held in the union is null, regardless of which type it is.
Definition: PointerUnion.h:178
bool is() const
Test if the Union currently holds the type matching T.
Definition: PointerUnion.h:183
PointerUnionMembers()=default
ValTy Val
Definition: PointerUnion.h:105
PointerUnionMembers()=default
PointerUnionMembers(Type V)
Definition: PointerUnion.h:120
Derived & operator=(Type V)
Definition: PointerUnion.h:126
Definition: PointerUnion.h:100
Provide PointerLikeTypeTraits for void* that is used by PointerUnion for the template arguments.
Definition: PointerUnion.h:92
static constexpr int NumLowBitsAvailable
Definition: PointerUnion.h:96
static void * getAsVoidPointer(void *P)
Definition: PointerUnion.h:94
static void * getFromVoidPointer(void *P)
Definition: PointerUnion.h:95
type
Definition: core.h:575
Type
Definition: Constants.h:471
Definition: format-inl.h:32
constexpr int lowBitsAvailable()
Definition: PointerUnion.h:81
constexpr int bitsRequired(unsigned n)
Determine the number of bits required to store integers with values < n.
Definition: PointerUnion.h:77
Definition: AprilTagFieldLayout.h:18
std::tuple_element_t< I, std::tuple< Ts... > > TypeAtIndex
Find the type at a given index in a list of types.
Definition: PointerUnion.h:72
bool operator<(PointerUnion< PTs... > lhs, PointerUnion< PTs... > rhs)
Definition: PointerUnion.h:249
bool operator==(const DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT > &LHS, const DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT > &RHS)
Equality comparison for DenseMap.
Definition: DenseMap.h:686
bool operator!=(const DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT > &LHS, const DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT > &RHS)
Inequality comparison for DenseMap.
Definition: DenseMap.h:706
static Union getTombstoneKey()
Definition: PointerUnion.h:279
static unsigned getHashValue(const Union &UnionVal)
Definition: PointerUnion.h:283
static bool isEqual(const Union &LHS, const Union &RHS)
Definition: PointerUnion.h:288
static Union getEmptyKey()
Definition: PointerUnion.h:277
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition: DenseMapInfo.h:49
Find the first index where a type appears in a list of types.
Definition: PointerUnion.h:61
static PointerUnion< PTs... > getFromVoidPointer(void *P)
Definition: PointerUnion.h:261
static void * getAsVoidPointer(const PointerUnion< PTs... > &P)
Definition: PointerUnion.h:257
A traits type that is used to handle pointer types and things that are just wrappers for pointers as ...
Definition: PointerLikeTypeTraits.h:25
Determine if all types in Ts are distinct.
Definition: PointerUnion.h:49
Definition: PointerUnion.h:34
Find the first type in a list of types.
Definition: PointerUnion.h:86
T type
Definition: PointerUnion.h:87