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
-
D | Derived type to check (potential reference and const qualifiers are removed). |
B | Base type to check (potential reference and const qualifiers are removed). |