A sum type over pointer‐like types.

Synopsis

Declared in <llvm/ADT/PointerSumType.h>

template<
    typename TagT,
    typename... MemberTs>
class PointerSumType;

Description

This is a normal tagged union across pointer‐like types that uses the low bits of the pointers to store the tag.

Each member of the sum type is specified by passing a PointerSumTypeMember specialization in the variadic member argument list. This allows the user to control the particular tag value associated with a particular type, use the same type for multiple different tags, and customize the pointer‐like traits used for a particular member. Note that these must be specializations of PointerSumTypeMember, no other type will suffice, even if it provides a compatible interface.

This type implements all of the comparison operators and even hash table support by comparing the underlying storage of the pointer values. It doesn't support delegating to particular members for comparisons.

It also default constructs to a zero tag with a null pointer, whatever that would be. This means that the zero value for the tag type is significant and may be desirable to set to a state that is particularly desirable to default construct.

Having a supported zero‐valued tag also enables getting the address of a pointer stored with that tag provided it is stored in its natural bit representation. This works because in the case of a zero‐valued tag, the pointer's value is directly stored into this object and we can expose the address of that internal storage. This is especially useful when building an ArrayRef of a single pointer stored in a sum type.

There is no support for constructing or accessing with a dynamic tag as that would fundamentally violate the type safety provided by the sum type.

Member Functions

Name

Description

PointerSumType [constructor]

Construct a null sum type with the minimum tag value.

cast

Return the pointer for tag N; asserts that tag is active.

clear

Clear the value to null with the min tag type.

get

Return the pointer for tag N, or null if that tag is inactive.

getAddrOfZeroTagPointer

If the tag is zero and the pointer's value isn't changed when being stored, get the address of the stored value type‐punned to the zero‐tag's pointer type.

getOpaqueValue

Return the raw tagged pointer bits.

getTag

Return the discriminant tag of the active member.

is

Return true if the active member has tag N.

set

A typed setter to a given tagged member of the sum type.

operator bool

Return true if the stored pointer bits are non‐null.

operator==

Compare two sum types by their opaque packed representation.

operator!=

Return true if the opaque representations differ.

operator<

Order by the opaque packed representation.

operator<=

Order by the opaque packed representation.

operator>

Order by the opaque packed representation.

operator>=

Order by the opaque packed representation.

Static Member Functions

Name

Description

create

A typed constructor for a specific tagged member of the sum type.

Protected Member Functions

Name

Description

getVoidPtr

Return the pointer bits with the tag cleared.

Created with MrDocs