33#ifndef DART_COMMON_DETAIL_CASTABLE_HPP_
34#define DART_COMMON_DETAIL_CASTABLE_HPP_
46template <
typename Base>
47template <
typename Derived>
54 return (base().getType() == Derived::getStaticType());
58 return (
dynamic_cast<const Derived*
>(&base()) !=
nullptr);
63template <
typename Base>
64template <
typename Derived>
67 return is<Derived>() ?
static_cast<const Derived*
>(&base()) :
nullptr;
71template <
typename Base>
72template <
typename Derived>
75 return is<Derived>() ?
static_cast<Derived*
>(&base()) : nullptr;
79template <
typename Base>
80template <
typename Derived>
83 assert(is<Derived>());
84 return *as<Derived>();
88template <
typename Base>
89template <
typename Derived>
92 assert(is<Derived>());
93 return *as<Derived>();
97template <
typename Base>
100 return *
static_cast<const Base*
>(
this);
104template <
typename Base>
107 return *
static_cast<Base*
>(
this);
const Base & base() const
Casts to Base const-reference.
Definition Castable-impl.hpp:98
const Derived & asRef() const
Casts to reference of Derived if Base is its base class. UB otherwise.
Definition Castable-impl.hpp:81
bool is() const
Returns true if the types of this Base and the template parameter (a base class) are identical.
Definition Castable-impl.hpp:48
const Derived * as() const
Casts to pointer of Derived if Base is its base class.
Definition Castable-impl.hpp:65
Definition Castable-impl.hpp:43
Definition Castable-impl.hpp:42