class PointerUnion
Declaration
template <typename... PTs>
class PointerUnion { /* full declaration omitted */ };
Description
A discriminated union of two or more pointer types, with the discriminator in the low bit of the pointer. This implementation is extremely efficient in space due to leveraging the low bits of the pointer, while exposing a natural and type-safe API. Common use patterns would be something like this: PointerUnion <int *, float*> P; P = (int*)0; printf("%d %d", P.is <int *>(), P.is <float *>()); // prints "1 0" X = P.get <int *>(); // ok. Y = P.get <float *>(); // runtime assertion failure. Z = P.get <double *>(); // compile time failure. P = (float*)0; Y = P.get <float *>(); // ok. X = P.get <int *>(); // runtime assertion failure. PointerUnion <int *, int*> Q; // compile time failure.
Declared at: llvm/include/llvm/ADT/PointerUnion.h:112
Templates
- PTs
Method Overview
- public PointerUnion<PTs...>()
- public PointerUnion<PTs...>(std::nullptr_t)
- public template <typename T>inline T dyn_cast() const
- public template <typename T>inline T get() const
- public const llvm::PointerUnion::First * getAddrOfPtr1() const
- public llvm::PointerUnion::First * getAddrOfPtr1()
- public static inline PointerUnion<PTs...> getFromOpaqueValue(void * VP)
- public void * getOpaqueValue() const
- public template <typename T>inline bool is() const
- public bool isNull() const
- public bool operator bool() const
Methods
¶PointerUnion<PTs...>()
PointerUnion<PTs...>()
Declared at: llvm/include/llvm/ADT/PointerUnion.h:135
¶PointerUnion<PTs...>(std::nullptr_t)
PointerUnion<PTs...>(std::nullptr_t)
Declared at: llvm/include/llvm/ADT/PointerUnion.h:137
Parameters
¶template <typename T>
inline T dyn_cast() const
template <typename T>
inline T dyn_cast() const
Description
Returns the current pointer if it is of the specified pointer type, otherwise returns null.
Declared at: llvm/include/llvm/ADT/PointerUnion.h:162
Templates
- T
¶template <typename T>
inline T get() const
template <typename T>
inline T get() const
Description
Returns the value of the specified pointer type. If the specified pointer type is incorrect, assert.
Declared at: llvm/include/llvm/ADT/PointerUnion.h:155
Templates
- T
¶const llvm::PointerUnion::First* getAddrOfPtr1()
const
const llvm::PointerUnion::First* getAddrOfPtr1()
const
Description
If the union is set to the first pointer type get an address pointing to it.
Declared at: llvm/include/llvm/ADT/PointerUnion.h:168
¶llvm::PointerUnion::First* getAddrOfPtr1()
llvm::PointerUnion::First* getAddrOfPtr1()
Description
If the union is set to the first pointer type get an address pointing to it.
Declared at: llvm/include/llvm/ADT/PointerUnion.h:174
¶static inline PointerUnion<PTs...>
getFromOpaqueValue(void* VP)
static inline PointerUnion<PTs...>
getFromOpaqueValue(void* VP)
Declared at: llvm/include/llvm/ADT/PointerUnion.h:194
Parameters
- void* VP
¶void* getOpaqueValue() const
void* getOpaqueValue() const
Declared at: llvm/include/llvm/ADT/PointerUnion.h:193
¶template <typename T>
inline bool is() const
template <typename T>
inline bool is() const
Description
Test if the Union currently holds the type matching T.
Declared at: llvm/include/llvm/ADT/PointerUnion.h:150
Templates
- T
¶bool isNull() const
bool isNull() const
Description
Test if the pointer held in the union is null, regardless of which type it is.
Declared at: llvm/include/llvm/ADT/PointerUnion.h:142
¶bool operator bool() const
bool operator bool() const
Declared at: llvm/include/llvm/ADT/PointerUnion.h:144