[#llvm-CastInfo-01] = xref:llvm.adoc[llvm]::CastInfo :relfileprefix: ../ :mrdocs: Customizes how casts from `From` to `To` are performed. == Synopsis Declared in `<llvm/Support/Casting.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< typename To, typename From, typename Enable = void> struct CastInfo : xref:llvm/CastIsPossible-05.adoc[CastIsPossible<To, From>] ---- == Description 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); } }; == Base Classes [cols="1,4"] |=== | Name| Description | `xref:llvm/CastIsPossible-05.adoc[CastIsPossible<To, From>]` | Trait that reports whether a cast from `From` to `To` is possible. |=== == Type Aliases [cols="1,4"] |=== | Name| Description | xref:llvm/CastInfo-01/CastReturnType.adoc[`CastReturnType`] | Return type produced by successful casts in this specialization. | xref:llvm/CastInfo-01/Self.adoc[`Self`] | This `CastInfo` specialization, used for CRTP‐style calls. |=== == Static Member Functions [cols="1,4"] |=== | Name| Description | xref:llvm/CastInfo-01/castFailed.adoc[`castFailed`] | Returns a null cast result used when the cast fails. | xref:llvm/CastInfo-01/doCast.adoc[`doCast`] | Unconditionally converts `f` to the cast return type. | xref:llvm/CastInfo-01/doCastIfPossible.adoc[`doCastIfPossible`] | Casts `f` if possible; otherwise returns `castFailed().` | xref:llvm/CastIsPossible-05/isPossible.adoc[`isPossible`] | Returns true if a cast from `f` to `To` is possible. |=== == Specializations [cols="1,4"] |=== | Name| Description | xref:llvm/CastInfo-0d.adoc[`CastInfo<To, IRUnitRef>`] | Lets isa/cast/dyn_cast query which IR unit an IRUnitRef holds, naming the IR unit itself rather than a pointer to it: dyn_cast<Module>(IR). | xref:llvm/CastInfo-09a.adoc[`CastInfo<To, IRUnitRef const>`] | CastInfo specialization for const IRUnitRef, forwarding to the non‐const case. | xref:llvm/CastInfo-05.adoc[`CastInfo<SCEVUseT<ToSCEVPtrT>, SCEVUse>`] | Provide CastInfo for SCEVUseT so that cast<SCEVUseT<const To *>>(use) returns SCEVUseT<const To *> with flags preserved. | xref:llvm/CastInfo-02b.adoc[`CastInfo<SCEVUseT<ToSCEVPtrT>, SCEVUse const>`] | CastInfo specialization for const SCEVUse, forwarding to the non‐const case. | xref:llvm/CastInfo-0b.adoc[`CastInfo<To, From>`] | Cast traits for DIExpression typed operand views. | xref:llvm/CastInfo-00.adoc[`CastInfo<To, From>`] | `CastInfo` specialization that forwards through `simplify_type.` | xref:llvm/CastInfo-06.adoc[`CastInfo<To, From>`] | `CastInfo` specialization that forwards through `simplify_type.` | xref:llvm/CastInfo-0f5.adoc[`CastInfo<To, PointerUnion<PTs...>>`] | CastInfo specialization for non‐const PointerUnion sources. | xref:llvm/CastInfo-0fe.adoc[`CastInfo<To, std::optional<From>>`] | Provide a CastInfo specialized for casting out of `std::optional.` | xref:llvm/CastInfo-094.adoc[`CastInfo<To, std::unique_ptr<From>>`] | Provide a CastInfo specialized for std::unique_ptr. | xref:llvm/CastInfo-024.adoc[`CastInfo<To, PointerUnion<PTs...> const>`] | CastInfo specialization for const PointerUnion sources. |=== == Derived Classes [cols="1,4"] |=== | Name| Description | xref:llvm/CastInfo-09a.adoc[`CastInfo<To, IRUnitRef const>`] | CastInfo specialization for const IRUnitRef, forwarding to the non‐const case. | xref:llvm/CastInfo-02b.adoc[`CastInfo<SCEVUseT<ToSCEVPtrT>, SCEVUse const>`] | CastInfo specialization for const SCEVUse, forwarding to the non‐const case. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#