LLVM 20.0.0git
Public Types | Static Public Member Functions | List of all members
llvm::CastInfo< To, From, Enable > Struct Template Reference

This struct provides a method for customizing the way a cast is performed. More...

#include "llvm/Support/Casting.h"

Inheritance diagram for llvm::CastInfo< To, From, Enable >:
Inheritance graph
[legend]

Public Types

using Self = CastInfo< To, From, Enable >
 
using CastReturnType = typename cast_retty< To, From >::ret_type
 

Static Public Member Functions

static CastReturnType doCast (const From &f)
 
static CastReturnType castFailed ()
 
static CastReturnType doCastIfPossible (const From &f)
 
- Static Public Member Functions inherited from llvm::CastIsPossible< To, From, Enable >
static bool isPossible (const From &f)
 

Detailed Description

template<typename To, typename From, typename Enable = void>
struct llvm::CastInfo< To, From, Enable >

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.

In order to specialize different behaviors, specify different functions in your CastInfo specialization. For isa<> customization, provide:

static bool isPossible(const From &f)

For cast<> customization, provide:

static To doCast(const From &f)

For dyn_cast<> and the *_if_present<> variants' customization, provide:

static To castFailed() and static To doCastIfPossible(const From &f)

Your specialization might look something like this:

template<> struct CastInfo<foo, bar> : public CastIsPossible<foo, bar> { static inline foo doCast(const bar &b) { return foo(const_cast<bar &>(b)); } static inline foo castFailed() { return foo(); } static inline foo doCastIfPossible(const bar &b) { if (!CastInfo<foo, bar>::isPossible(b)) return castFailed(); return doCast(b); } };

Definition at line 476 of file Casting.h.

Member Typedef Documentation

◆ CastReturnType

template<typename To , typename From , typename Enable = void>
using llvm::CastInfo< To, From, Enable >::CastReturnType = typename cast_retty<To, From>::ret_type

Definition at line 479 of file Casting.h.

◆ Self

template<typename To , typename From , typename Enable = void>
using llvm::CastInfo< To, From, Enable >::Self = CastInfo<To, From, Enable>

Definition at line 477 of file Casting.h.

Member Function Documentation

◆ castFailed()

template<typename To , typename From , typename Enable = void>
static CastReturnType llvm::CastInfo< To, From, Enable >::castFailed ( )
inlinestatic

◆ doCast()

template<typename To , typename From , typename Enable = void>
static CastReturnType llvm::CastInfo< To, From, Enable >::doCast ( const From f)
inlinestatic

Definition at line 481 of file Casting.h.

References From.

Referenced by llvm::cast(), and llvm::CastInfo< To, From, Enable >::doCastIfPossible().

◆ doCastIfPossible()

template<typename To , typename From , typename Enable = void>
static CastReturnType llvm::CastInfo< To, From, Enable >::doCastIfPossible ( const From f)
inlinestatic

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