Raven Engine v0.1
Loading...
Searching...
No Matches
Raven::Castable< Derived > Class Template Reference

CRTP base class enabling self-casting in derived types. More...

#include <Casting.h>

Public Member Functions

template<typename T>
requires std::derived_from<T, Derived>
T & As ()
 Non-const version of As<T>(), for casting to a non-const target type.
template<typename T>
requires std::derived_from<T, Derived>
const T & As () const
 Const version of As<T>(), for casting to a const target type.

Detailed Description

template<typename Derived>
class Raven::Castable< Derived >

CRTP base class enabling self-casting in derived types.

This class provides the As<T>() method for derived classes, enabling safe casting within a CRTP hierarchy.

Typical usage:

  1. Derive from Castable<T> to enable self-casting in your class.
  2. Use As<T>() to safely cast an object of type Derived to T.
Template Parameters
DerivedThe derived class using this CRTP base class.

Member Function Documentation

◆ As() [1/2]

template<typename Derived>
template<typename T>
requires std::derived_from<T, Derived>
T & Raven::Castable< Derived >::As ( )
inline

Non-const version of As<T>(), for casting to a non-const target type.

This method is used for casting a Derived type to another type T, and allows modification of the casted object.

Template Parameters
TThe target type to cast to.
Returns
A reference to the casted object of type T.

◆ As() [2/2]

template<typename Derived>
template<typename T>
requires std::derived_from<T, Derived>
const T & Raven::Castable< Derived >::As ( ) const
inline

Const version of As<T>(), for casting to a const target type.

This method is used for casting a Derived type to another type T, and ensures the casted object remains constant.

Template Parameters
TThe target type to cast to.
Returns
A const reference to the casted object of type T.

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