Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

is_base_of

template <class Base, class Derived>
struct is_base_of : public true_type-or-false_type {};

Inherits: If Base is base class of type Derived or if both types are the same then inherits from true_type, otherwise inherits from false_type.

This template will detect non-public base classes, and ambiguous base classes.

Note that is_base_of<X,X> will always inherit from true_type. This is the case even if X is not a class type. This is a change in behaviour from Boost-1.33 in order to track the Technical Report on C++ Library Extensions.

Types Base and Derived must not be incomplete types.

C++ Standard Reference: 10.

Header: #include <boost/type_traits/is_base_of.hpp> or #include <boost/type_traits.hpp>

Compiler Compatibility: If the compiler does not support partial-specialization of class templates, then this template can not be used with function types. There are some older compilers which will produce compiler errors if Base is a private base class of Derived, or if Base is an ambiguous base of Derived. These compilers include Borland C++, older versions of Sun Forte C++, Digital Mars C++, and older versions of EDG based compilers.

Examples:

Given: class Base{}; class Derived : public Base{};

is_base_of<Base, Derived> inherits from true_type.

is_base_of<Base, Derived>::type is the type true_type.

is_base_of<Base, Derived>::value is an integral constant expression that evaluates to true.

is_base_of<Base, Base>::value is an integral constant expression that evaluates to true: a class is regarded as it's own base.

is_base_of<T, T>::value_type is the type bool.


PrevUpHomeNext