]>
Commit | Line | Data |
---|---|---|
1 | [/ | |
2 | Copyright 2007 John Maddock. | |
3 | Distributed under the Boost Software License, Version 1.0. | |
4 | (See accompanying file LICENSE_1_0.txt or copy at | |
5 | http://www.boost.org/LICENSE_1_0.txt). | |
6 | ] | |
7 | ||
8 | [section:is_base_of is_base_of] | |
9 | ||
10 | template <class Base, class Derived> | |
11 | struct is_base_of : public __tof {}; | |
12 | ||
13 | __inherit If Base is base class of type Derived or if both types are the same | |
14 | class type then inherits from __true_type, | |
15 | otherwise inherits from __false_type. | |
16 | ||
17 | This template will detect non-public base classes, and ambiguous base classes. | |
18 | It also detects indirect base classes - which is to say __is_base_of<B, D> inherits | |
19 | from __true_type if B is located anywhere in the inheritance tree of D. | |
20 | ||
21 | Note that `is_base_of<X,X>` will inherit from __true_type if X is a class type. | |
22 | This is a change in behaviour | |
23 | from Boost-1.39.0 in order to track the emerging C++0x standard. | |
24 | ||
25 | Types `Base` and `Derived` must not be incomplete types. | |
26 | ||
27 | __std_ref 10. | |
28 | ||
29 | __header ` #include <boost/type_traits/is_base_of.hpp>` or ` #include <boost/type_traits.hpp>` | |
30 | ||
31 | [all_compilers] | |
32 | ||
33 | __examples | |
34 | ||
35 | [:Given: ` class Base{}; class Derived : public Base{};` ] | |
36 | ||
37 | [:`is_base_of<Base, Derived>` inherits from `__true_type`.] | |
38 | ||
39 | [:`is_base_of<Base, Derived>::type` is the type `__true_type`.] | |
40 | ||
41 | [:`is_base_of<Base, Derived>::value` is an integral constant | |
42 | expression that evaluates to /true/.] | |
43 | ||
44 | [:`is_base_of<Base, Base>::value` is an integral constant | |
45 | expression that evaluates to /true/: a class is regarded as it's own base.] | |
46 | ||
47 | [:`is_base_of<T, T>::value_type` is the type `bool`.] | |
48 | ||
49 | [endsect] | |
50 | ||
51 | ||
52 |