LLVM 22.0.0git
llvm::TypeSwitch< T, ResultT > Class Template Reference

This class implements a switch-like dispatch statement for a value of 'T' using dyn_cast functionality. More...

#include "llvm/ADT/TypeSwitch.h"

Inheritance diagram for llvm::TypeSwitch< T, ResultT >:
[legend]

Public Types

using BaseT = detail::TypeSwitchBase<TypeSwitch<T, ResultT>, T>

Public Member Functions

 TypeSwitch (TypeSwitch &&other)=default
template<typename CaseT, typename CallableT>
TypeSwitch< T, ResultT > & Case (CallableT &&caseFn)
 Add a case on the given type.
template<typename CallableT>
ResultT Default (CallableT &&defaultFn)
 As a default, invoke the given callable within the root value.
ResultT Default (ResultT defaultResult)
 As a default, return the given value.
 operator ResultT ()
Public Member Functions inherited from llvm::detail::TypeSwitchBase< TypeSwitch< T, void >, T >
 TypeSwitchBase (const T &value)
 TypeSwitchBase (TypeSwitchBase &&other)
 ~TypeSwitchBase ()=default
 TypeSwitchBase (const TypeSwitchBase &)=delete
 TypeSwitchBase is not copyable.
void operator= (const TypeSwitchBase &)=delete
void operator= (TypeSwitchBase &&other)=delete
LLVM_ATTRIBUTE_ALWAYS_INLINE LLVM_ATTRIBUTE_NODEBUG TypeSwitch< T, void > & Case (CallableT &&caseFn)
 Invoke a case on the derived class with multiple case types.
TypeSwitch< T, void > & Case (CallableT &&caseFn)
 Invoke a case on the derived class, inferring the type of the Case from the first input of the given callable.

Additional Inherited Members

Static Protected Member Functions inherited from llvm::detail::TypeSwitchBase< TypeSwitch< T, void >, T >
static decltype(auto) castValue (ValueT &&value)
 Attempt to dyn_cast the given value to CastT.
Protected Attributes inherited from llvm::detail::TypeSwitchBase< TypeSwitch< T, void >, T >
const T value
 The root value we are switching on.

Detailed Description

template<typename T, typename ResultT = void>
class llvm::TypeSwitch< T, ResultT >

This class implements a switch-like dispatch statement for a value of 'T' using dyn_cast functionality.

Each Case<T> takes a callable to be invoked if the root value isa<T>, the callable is invoked with the result of dyn_cast<T>() as a parameter.

Example: Operation *op = ...; LogicalResult result = TypeSwitch<Operation *, LogicalResult>(op) .Case<ConstantOp>([](ConstantOp op) { ... }) .Default([](Operation *op) { ... });

Definition at line 87 of file TypeSwitch.h.

Member Typedef Documentation

◆ BaseT

template<typename T, typename ResultT = void>
using llvm::TypeSwitch< T, ResultT >::BaseT = detail::TypeSwitchBase<TypeSwitch<T, ResultT>, T>

Definition at line 89 of file TypeSwitch.h.

Constructor & Destructor Documentation

◆ TypeSwitch()

template<typename T, typename ResultT = void>
llvm::TypeSwitch< T, ResultT >::TypeSwitch ( TypeSwitch< T, ResultT > && other)
default

References TypeSwitch().

Referenced by Case(), and TypeSwitch().

Member Function Documentation

◆ Case()

template<typename T, typename ResultT = void>
template<typename CaseT, typename CallableT>
TypeSwitch< T, ResultT > & llvm::TypeSwitch< T, ResultT >::Case ( CallableT && caseFn)
inline

◆ Default() [1/2]

template<typename T, typename ResultT = void>
template<typename CallableT>
ResultT llvm::TypeSwitch< T, ResultT >::Default ( CallableT && defaultFn)
inlinenodiscard

As a default, invoke the given callable within the root value.

Definition at line 108 of file TypeSwitch.h.

References llvm::detail::TypeSwitchBase< TypeSwitch< T, void >, T >::value.

◆ Default() [2/2]

template<typename T, typename ResultT = void>
ResultT llvm::TypeSwitch< T, ResultT >::Default ( ResultT defaultResult)
inlinenodiscard

As a default, return the given value.

Definition at line 114 of file TypeSwitch.h.

◆ operator ResultT()

template<typename T, typename ResultT = void>
llvm::TypeSwitch< T, ResultT >::operator ResultT ( )
inlinenodiscard

Definition at line 120 of file TypeSwitch.h.

References assert().


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