cereal::detail::PolymorphicCasters(3) Library Functions Manual cereal::detail::PolymorphicCasters(3)

# [NAME](#NAME)

cereal::detail::PolymorphicCasters - Holds registered mappings between base and derived types for casting.

# [SYNOPSIS](#SYNOPSIS)

#include &lt;/home/build/include/cereal/details/polymorphic\_impl.hpp&gt;

## [Public Types](#Public_Types)

using **DerivedCasterMap** = std::unordered\_map&lt;std::type\_index, std::vector&lt;**PolymorphicCaster** const \*&gt;&gt;  
Maps from a derived type index to a set of chainable casters.

## [Static Public Member Functions](#Static_Public_Member_Functions)

static std::pair&lt; bool, std::vector&lt; **PolymorphicCaster** const * &gt; const & &gt; **lookup\_if\_exists** (std::type\_index const &baseIndex, std::type\_index const &derivedIndex)  
Checks if the mapping object that can perform the upcast or downcast exists, and returns it if so. template&lt;class F&gt; static std::vector&lt; **PolymorphicCaster** const * &gt; const & **lookup** (std::type\_index const &baseIndex, std::type\_index const &derivedIndex, F &&exceptionFunc)  
Gets the mapping object that can perform the upcast or downcast. template&lt;class Derived&gt; static const Derived * **downcast** (const void \*dptr, std::type\_info const &baseInfo)  
Performs a downcast to the derived type using a registered mapping. template&lt;class Derived&gt; static void * **upcast** (Derived \*const dptr, std::type\_info const &baseInfo)  
Performs an upcast to the registered base type using the given a derived type. template&lt;class Derived&gt; static std::shared\_ptr&lt; void &gt; **upcast** (std::shared\_ptr&lt; Derived &gt; const &dptr, std::type\_info const &baseInfo)  
Upcasts for shared pointers.

## [Public Attributes](#Public_Attributes)

std::unordered\_map&lt; std::type\_index, **DerivedCasterMap** &gt; **map**  
Maps from base type index to a map from derived type index to caster. std::multimap&lt; std::type\_index, std::type\_index &gt; **reverseMap**

# [Detailed Description](#Detailed_Description)

Holds registered mappings between base and derived types for casting.

This will be allocated as a **StaticObject** and holds a map containing all registered mappings between base and derived types.

# [Member Function Documentation](#Member_Function_Documentation)

## [template&lt;class F&gt; std::vector&lt; **PolymorphicCaster** const * &gt; const & cereal::detail::PolymorphicCasters::lookup (std::type\_index const & baseIndex, std::type\_index const & derivedIndex, F && exceptionFunc) \[inline\], \[static\]](#template_class_F__std::vector__)

Gets the mapping object that can perform the upcast or downcast. Uses the type index from the base and derived class to find the matching registered caster. If no matching caster exists, calls the exception function.

The returned **PolymorphicCaster** is capable of upcasting or downcasting between the two types.

## [std::pair&lt; bool, std::vector&lt; **PolymorphicCaster** const * &gt; const & &gt; cereal::detail::PolymorphicCasters::lookup\_if\_exists (std::type\_index const & baseIndex, std::type\_index const & derivedIndex) \[inline\], \[static\]](#std::pair__bool,_std::vector__)

Checks if the mapping object that can perform the upcast or downcast exists, and returns it if so. Uses the type index from the base and derived class to find the matching registered caster. If no matching caster exists, the bool in the pair will be false and the vector reference should not be used.

## [template&lt;class Derived&gt; void * cereal::detail::PolymorphicCasters::upcast (Derived \*const dptr, std::type\_info const & baseInfo) \[inline\], \[static\]](#template_class_Derived__void_*_cereal::detail::PolymorphicCasters::upcast_%28Derived_*const_dptr,_std::type_info_const_&_baseInfo%29)

Performs an upcast to the registered base type using the given a derived type. The return is untyped because the final casting to the base type must happen in the polymorphic serialization function, where the type is known at compile time

# [Author](#Author)

Generated automatically by Doxygen for cereal from the source code.

Sat Aug 29 2026 00:42:30 cereal

---

Document: cereal_detail_PolymorphicCasters(3) from cereal 1.3.2-r5 (Chainguard OS)
Source: https://github.com/USCiLab/cereal
