LLVM  10.0.0svn
Public Member Functions | Static Public Member Functions | List of all members
llvm::PointerUnion< PTs > Class Template Reference

A discriminated union of two or more pointer types, with the discriminator in the low bit of the pointer. More...

#include "llvm/ADT/PointerUnion.h"

Inheritance diagram for llvm::PointerUnion< PTs >:
Inheritance graph
[legend]
Collaboration diagram for llvm::PointerUnion< PTs >:
Collaboration graph
[legend]

Public Member Functions

 PointerUnion ()=default
 
 PointerUnion (std::nullptr_t)
 
bool isNull () const
 Test if the pointer held in the union is null, regardless of which type it is. More...
 
 operator bool () const
 
template<typename T >
int is () const
 Test if the Union currently holds the type matching T. More...
 
template<typename T >
T get () const
 Returns the value of the specified pointer type. More...
 
template<typename T >
T dyn_cast () const
 Returns the current pointer if it is of the specified pointer type, otherwises returns null. More...
 
First constgetAddrOfPtr1 () const
 If the union is set to the first pointer type get an address pointing to it. More...
 
First * getAddrOfPtr1 ()
 If the union is set to the first pointer type get an address pointing to it. More...
 
const PointerUnionoperator= (std::nullptr_t)
 Assignment from nullptr which just clears the union. More...
 
void * getOpaqueValue () const
 

Static Public Member Functions

static PointerUnion getFromOpaqueValue (void *VP)
 

Detailed Description

template<typename... PTs>
class llvm::PointerUnion< PTs >

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.

Definition at line 163 of file PointerUnion.h.

Constructor & Destructor Documentation

◆ PointerUnion() [1/2]

template<typename... PTs>
llvm::PointerUnion< PTs >::PointerUnion ( )
default

◆ PointerUnion() [2/2]

template<typename... PTs>
llvm::PointerUnion< PTs >::PointerUnion ( std::nullptr_t  )
inline

Definition at line 180 of file PointerUnion.h.

Member Function Documentation

◆ dyn_cast()

template<typename... PTs>
template<typename T >
T llvm::PointerUnion< PTs >::dyn_cast ( ) const
inline

◆ get()

template<typename... PTs>
template<typename T >
T llvm::PointerUnion< PTs >::get ( ) const
inline

◆ getAddrOfPtr1() [1/2]

template<typename... PTs>
First const* llvm::PointerUnion< PTs >::getAddrOfPtr1 ( ) const
inline

◆ getAddrOfPtr1() [2/2]

template<typename... PTs>
First* llvm::PointerUnion< PTs >::getAddrOfPtr1 ( )
inline

If the union is set to the first pointer type get an address pointing to it.

Definition at line 226 of file PointerUnion.h.

◆ getFromOpaqueValue()

template<typename... PTs>
static PointerUnion llvm::PointerUnion< PTs >::getFromOpaqueValue ( void *  VP)
inlinestatic

◆ getOpaqueValue()

template<typename... PTs>
void* llvm::PointerUnion< PTs >::getOpaqueValue ( ) const
inline

◆ is()

template<typename... PTs>
template<typename T >
int llvm::PointerUnion< PTs >::is ( ) const
inline

◆ isNull()

template<typename... PTs>
bool llvm::PointerUnion< PTs >::isNull ( ) const
inline

◆ operator bool()

template<typename... PTs>
llvm::PointerUnion< PTs >::operator bool ( ) const
inlineexplicit

Definition at line 192 of file PointerUnion.h.

◆ operator=()

template<typename... PTs>
const PointerUnion& llvm::PointerUnion< PTs >::operator= ( std::nullptr_t  )
inline

Assignment from nullptr which just clears the union.

Definition at line 236 of file PointerUnion.h.


The documentation for this class was generated from the following file: