HasBaseDetector< D, B > Struct Template Reference

#include <apibase.h>

Detailed Description

template<typename D, typename B>
struct maxon::HasBaseDetector< D, B >

This type trait checks if D has B as its base. This is the case if both are the same, or if both are virtual interfaces and D is (directly or indirecty) derived from B, or if D is derived from B as a C++ class.

If D has B as its base, the function HasBaseDetector<D, B>Cast can be used to cast a pointer of the derived type to a pointer of the base type. This has to be used instead of a reinterpret_cast because the latter doesn't handle correctly cases with virtual classes or multiple inheritance when there are offsets between derived and base pointers.

Internally, if D has a member type HasBaseDetector, the check is forwarded to D::HasBaseDetector::Check<B> which implements the case for virtual interfaces. Otherwise, the check is simply forwarded to std::is_base_of<B, D>.

Template Parameters
DDerived type to check (potential reference and const qualifiers are removed).
BBase type to check (potential reference and const qualifiers are removed).

Public Types

using DT = typename std::decay< D >::type
 
using BT = typename std::decay< B >::type
 
using Helper = maxon::details::HasBaseHelper< DT, BT, maxon::details::CheckHasBaseHelper< DT, BT >::value >
 

Static Public Member Functions

static BTCast (DT *ptr)
 
static const BTCast (const DT *ptr)
 

Static Public Attributes

static const Bool value
 

Member Typedef Documentation

◆ DT

using DT = typename std::decay<D>::type

◆ BT

using BT = typename std::decay<B>::type

◆ Helper

Member Function Documentation

◆ Cast() [1/2]

static BT* Cast ( DT ptr)
static

◆ Cast() [2/2]

static const BT* Cast ( const DT ptr)
static

Member Data Documentation

◆ value

const Bool value
static