LLVM  mainline
llvm::PointerUnion< PT1, PT2 > Class Template Reference

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

#include <PointerUnion.h>

Inheritance diagram for llvm::PointerUnion< PT1, PT2 >:
Inheritance graph
[legend]

Detailed Description

template<typename PT1, typename PT2>
class llvm::PointerUnion< PT1, PT2 >

A discriminated union of two 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 83 of file PointerUnion.h.


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