Shared/Base/TypeInfo.h file

Function Death::runtime_cast()

Namespaces

namespace Death
Shared root namespace.

Functions

template<typename T, typename U>
auto runtime_cast(U* u) -> T noexcept
Casts a pointer to another type.
template<typename T, typename U>
auto runtime_cast(const U* u) -> T noexcept
template<typename T, typename U>
auto runtime_cast(const std::shared_ptr<U>& u) -> T noexcept
template<typename T, typename U>
auto runtime_cast(const std::unique_ptr<U>& u) -> T noexcept
template<typename T, typename U>
auto runtime_cast(U* u) -> T noexcept
Casts a pointer to another type.

Defines

#define DEATH_RUNTIME_OBJECT(...)
Class annotation to enable optimized runtime_cast<T>() functionality.

Function documentation

template<typename T, typename U>
T runtime_cast(U* u) noexcept

Casts a pointer to another type.

Safely converts pointers to classes up, down, and sideways along the inheritance hierarchy of classes annotated by DEATH_RUNTIME_OBJECT() in an optimized way. Additionally, it can perform downcast at no performance cost. It also pulls the actual pointer from std::shared_ptr and std::unique_ptr without taking ownership.

If DEATH_NO_RUNTIME_CAST is defined, the optimized implementation is suppressed and the standard dynamic_cast<T>() is used to cast the pointer instead.