15#ifndef WPIUTIL_WPI_POINTERUNION_H
16#define WPIUTIL_WPI_POINTERUNION_H
32template <
typename T,
typename... Us>
34 : std::integral_constant<bool, !std::disjunction_v<std::is_same<T, Us>...> &&
35 TypesAreDistinct<Us...>::value> {};
48template <
typename... Ts>
50 : std::integral_constant<bool, detail::TypesAreDistinct<Ts...>::value> {};
63template <
typename T,
typename U,
typename... Us>
65 : std::integral_constant<size_t, 1 + FirstIndexOfType<T, Us...>::value> {};
66template <
typename T,
typename... Us>
72template <
size_t I,
typename... Ts>
73using TypeAtIndex = std::tuple_element_t<I, std::tuple<Ts...>>;
100 template <
typename Derived,
typename ValTy,
int I,
typename ...Types>
103 template <
typename Derived,
typename ValTy,
int I>
113 template <
typename Derived,
typename ValTy,
int I,
typename Type,
122 : Base(ValTy(const_cast<void *>(
126 using Base::operator=;
131 return static_cast<Derived &
>(*this);
138template <
typename... PTs>
struct CastInfoPointerUnionImpl;
156template <
typename... PTs>
159 PointerUnion<PTs...>,
161 void *, pointer_union_detail::bitsRequired(sizeof...(PTs)), int,
162 pointer_union_detail::PointerUnionUIntTraits<PTs...>>,
165 "PointerUnion alternative types cannot be repeated");
172 using Base =
typename PointerUnion::PointerUnionMembers;
187 bool isNull()
const {
return !this->Val.getPointer(); }
189 explicit operator bool()
const {
return !
isNull(); }
195 template <
typename T>
196 [[deprecated(
"Use isa instead")]]
197 inline bool is()
const {
204 template <
typename T>
205 [[deprecated(
"Use cast instead")]]
207 assert(
isa<T>(*
this) &&
"Invalid accessor called");
226 assert(
isa<First>(*
this) &&
"Val is not the first pointer");
229 this->Val.getPointer() &&
230 "Can't get the address because PointerLikeTypeTraits changes the ptr");
231 return const_cast<First *
>(
232 reinterpret_cast<const First *
>(this->Val.getAddrOfPointer()));
237 this->Val.initWithPointer(
nullptr);
242 using Base::operator=;
252template <
typename ...PTs>
257template <
typename ...PTs>
262template <
typename ...PTs>
291template <
typename To,
typename... PTs>
294 CastInfo<To, PointerUnion<PTs...>>> {
307template <
typename To,
typename... PTs>
310 CastInfo<To, PointerUnion<PTs...>>> {
315template <
typename ...PTs>
318 return P.getOpaqueValue();
340 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.hpp:163
T dyn_cast() const
Returns the current pointer if it is of the specified pointer type, otherwise returns null.
Definition PointerUnion.hpp:213
T get() const
Returns the value of the specified pointer type.
Definition PointerUnion.hpp:206
First const * getAddrOfPtr1() const
If the union is set to the first pointer type get an address pointing to it.
Definition PointerUnion.hpp:219
void * getOpaqueValue() const
Definition PointerUnion.hpp:244
bool isNull() const
Test if the pointer held in the union is null, regardless of which type it is.
Definition PointerUnion.hpp:187
static PointerUnion getFromOpaqueValue(void *VP)
Definition PointerUnion.hpp:245
First * getAddrOfPtr1()
If the union is set to the first pointer type get an address pointing to it.
Definition PointerUnion.hpp:225
bool is() const
Test if the Union currently holds the type matching T.
Definition PointerUnion.hpp:197
PointerUnion(std::nullptr_t)
Definition PointerUnion.hpp:182
const PointerUnion & operator=(std::nullptr_t)
Assignment from nullptr which just clears the union.
Definition PointerUnion.hpp:236
ValTy Val
Definition PointerUnion.hpp:106
PointerUnionMembers()=default
Derived & operator=(Type V)
Definition PointerUnion.hpp:127
PointerUnionMembers()=default
PointerUnionMembers(Type V)
Definition PointerUnion.hpp:121
Definition PointerUnion.hpp:101
Provide PointerLikeTypeTraits for void* that is used by PointerUnion for the template arguments.
Definition PointerUnion.hpp:93
static void * getAsVoidPointer(void *P)
Definition PointerUnion.hpp:95
static constexpr int NumLowBitsAvailable
Definition PointerUnion.hpp:97
static void * getFromVoidPointer(void *P)
Definition PointerUnion.hpp:96
These are wrappers over isa* function that allow them to be used in generic algorithms such as wpi::u...
Definition type_traits.hpp:71
Definition PointerUnion.hpp:75
constexpr int bitsRequired(unsigned n)
Determine the number of bits required to store integers with values < n.
Definition PointerUnion.hpp:78
constexpr int lowBitsAvailable()
Definition PointerUnion.hpp:82
Definition raw_os_ostream.hpp:19
constexpr bool operator<(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition expected:184
constexpr bool operator!=(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition expected:180
auto dyn_cast_if_present(const Y &Val)
dyn_cast_if_present<X> - Functionally identical to dyn_cast, except that a null (or none in the case ...
Definition Casting.hpp:738
std::tuple_element_t< I, std::tuple< Ts... > > TypeAtIndex
Find the type at a given index in a list of types.
Definition PointerUnion.hpp:73
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.hpp:565
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.hpp:548
constexpr bool operator==(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition expected:176
static To castFailed()
Definition PointerUnion.hpp:304
PointerUnion< PTs... > From
Definition PointerUnion.hpp:295
CastInfoPointerUnionImpl< PTs... > Impl
Definition PointerUnion.hpp:296
static bool isPossible(From &f)
Definition PointerUnion.hpp:298
static To doCast(From &f)
Definition PointerUnion.hpp:302
This struct provides a method for customizing the way a cast is performed.
Definition Casting.hpp:476
static CastReturnType doCast(const From &f)
Definition Casting.hpp:481
We can't (at least, at this moment with C++14) declare CastInfo as a friend of PointerUnion like this...
Definition PointerUnion.hpp:277
static bool isPossible(From &F)
Definition PointerUnion.hpp:280
static To doCast(From &F)
Definition PointerUnion.hpp:284
PointerUnion< PTs... > From
Definition PointerUnion.hpp:278
static bool isPossible(const From &f)
Definition Casting.hpp:254
Provides a cast trait that strips const from types to make it easier to implement a const-version of ...
Definition Casting.hpp:388
This cast trait just provides the default implementation of doCastIfPossible to make CastInfo special...
Definition Casting.hpp:309
static Union getEmptyKey()
Definition PointerUnion.hpp:337
PointerUnion< PTs... > Union
Definition PointerUnion.hpp:333
static bool isEqual(const Union &LHS, const Union &RHS)
Definition PointerUnion.hpp:348
static unsigned getHashValue(const Union &UnionVal)
Definition PointerUnion.hpp:343
DenseMapInfo< typename pointer_union_detail::GetFirstType< PTs... >::type > FirstInfo
Definition PointerUnion.hpp:334
static Union getTombstoneKey()
Definition PointerUnion.hpp:339
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition DenseMapInfo.hpp:52
Find the first index where a type appears in a list of types.
Definition PointerUnion.hpp:62
static constexpr int NumLowBitsAvailable
Definition PointerUnion.hpp:327
static void * getAsVoidPointer(const PointerUnion< PTs... > &P)
Definition PointerUnion.hpp:317
static PointerUnion< PTs... > getFromVoidPointer(void *P)
Definition PointerUnion.hpp:321
A traits type that is used to handle pointer types and things that are just wrappers for pointers as ...
Definition PointerLikeTypeTraits.hpp:25
Determine if all types in Ts are distinct.
Definition PointerUnion.hpp:50
Definition PointerUnion.hpp:35
Find the first type in a list of types.
Definition PointerUnion.hpp:87
T type
Definition PointerUnion.hpp:88