WPILibC++ 2024.1.1-beta-4
wpi::CastInfo< To, From, Enable > Struct Template Reference

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

#include </home/runner/work/allwpilib/allwpilib/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Casting.h>

Inheritance diagram for wpi::CastInfo< To, From, Enable >:
wpi::CastIsPossible< To, From, Enable >

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 wpi::CastIsPossible< To, From, Enable >
static bool isPossible (const From &f)
 

Detailed Description

template<typename To, typename From, typename Enable = void>
struct wpi::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); } };

Member Typedef Documentation

◆ CastReturnType

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

◆ Self

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

Member Function Documentation

◆ castFailed()

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

◆ doCast()

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

◆ doCastIfPossible()

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

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