FE 0.10.2
Header-only C++ frontend library
Loading...
Searching...
No Matches
fe::RuntimeCast< B > Class Template Reference

Inherit from this class using CRTP, for some nice dynamic_cast-style wrappers. More...

#include <fe/cast.h>

Public Member Functions

template<class T>
T * as ()
 static_cast with debug check.
template<class T>
T * isa ()
 dynamic_cast.
template<class T>
const T * as () const
 const version.
template<class T>
const T * isa () const
 const version.
template<class T, class... Args>
T * expect (std::format_string< Args... > fmt, Args &&... args)
 Like as() but - instead of merely asserting via isa() in Debug builds - throws a std::logic_error with a formatted message when the cast fails.
template<class T, class... Args>
const T * expect (std::format_string< Args... > fmt, Args &&... args) const
 const version.

Detailed Description

template<class B>
class fe::RuntimeCast< B >

Inherit from this class using CRTP, for some nice dynamic_cast-style wrappers.

Definition at line 20 of file cast.h.

Member Function Documentation

◆ as() [1/2]

template<class B>
template<class T>
T * fe::RuntimeCast< B >::as ( )
inline

static_cast with debug check.

Definition at line 24 of file cast.h.

References isa().

Referenced by as().

◆ as() [2/2]

template<class B>
template<class T>
const T * fe::RuntimeCast< B >::as ( ) const
inline

const version.

Definition at line 37 of file cast.h.

References as().

◆ expect() [1/2]

template<class B>
template<class T, class... Args>
T * fe::RuntimeCast< B >::expect ( std::format_string< Args... > fmt,
Args &&... args )
inline

Like as() but - instead of merely asserting via isa() in Debug builds - throws a std::logic_error with a formatted message when the cast fails.

fmt / args describe what was expected: a plain string works, as does a format string plus arguments. If B is std::formattable, the offending object is appended to the message.

Definition at line 46 of file cast.h.

References isa(), and fe::throwf().

Referenced by expect().

◆ expect() [2/2]

template<class B>
template<class T, class... Args>
const T * fe::RuntimeCast< B >::expect ( std::format_string< Args... > fmt,
Args &&... args ) const
inline

const version.

Definition at line 57 of file cast.h.

References expect().

◆ isa() [1/2]

template<class B>
template<class T>
T * fe::RuntimeCast< B >::isa ( )
inline

dynamic_cast.

If T isa fe::Nodeable, it will use node(), otherwise a dynamic_cast.

Definition at line 29 of file cast.h.

Referenced by as(), expect(), and isa().

◆ isa() [2/2]

template<class B>
template<class T>
const T * fe::RuntimeCast< B >::isa ( ) const
inline

const version.

Definition at line 38 of file cast.h.

References isa().


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