A discriminated union of two or more pointer types, with the discriminator in the low bits of the pointer.
Synopsis
Declared in <llvm/ADT/PointerUnion.h>
template<typename... PTs>
class PointerUnion
: public pointer_union_detail::PointerUnionMembers<PointerUnion<PTs...>, 0, PTs...>
Description
This implementation is extremely efficient in space due to leveraging the low bits of the pointer, while exposing a natural and type‐safe API.
When all types have enough alignment for a fixed‐width tag, the tag is placed in the high end of the available low bits, leaving spare low bits for nesting in PointerIntPair or SmallPtrSet. When types have heterogeneous alignment, a variable‐length escape‐encoded tag is used; in that case, types must be listed in non‐decreasing NumLowBitsAvailable order.
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.
Base Classes
Name |
Description |
CRTP base that generates non‐template constructors and assignment operators for each type in the union. Non‐template constructors allow implicit conversions (derived‐to‐base, non‐const‐to‐const). |
Member Functions
Name |
Description |
|
Constructors |
Assignment from nullptr clears the union, resetting to the first type. |
|
Returns the current pointer if it is of the specified pointer type, otherwise returns null. |
|
If the union is set to the first pointer type get an address pointing to it. |
|
Return the packed pointer and tag bits as an opaque void pointer. |
|
Test if the pointer held in the union is null, regardless of which type it is. |
|
Return true if the held pointer is non‐null. |
Static Member Functions
Name |
Description |
Reconstruct a PointerUnion from opaque void pointer |
Using Declarations
Friends
Name |
Description |
Order unions by their opaque bit patterns. |
|
Compare two unions for inequality of their opaque bit patterns. |
|
Compare two unions for equality of their opaque bit patterns. |
|
A traits type that is used to handle pointer types and things that are just wrappers for pointers as a uniform entity. |
|
This struct provides a method for customizing the way a cast is performed. It inherits from CastIsPossible, to support the case of declaring many CastIsPossible specializations without having to specialize the full CastInfo. |
|
|
CRTP base that generates non‐template constructors and assignment operators for each type in the union. Non‐template constructors allow implicit conversions (derived‐to‐base, non‐const‐to‐const). |
Created with MrDocs