]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | [/ |
2 | Copyright 2014 Peter Dimov | |
3 | ||
4 | Distributed under the Boost Software License, Version 1.0. | |
5 | ||
6 | See accompanying file LICENSE_1_0.txt | |
7 | or copy at http://boost.org/LICENSE_1_0.txt | |
8 | ] | |
9 | ||
10 | [section:typeinfo typeinfo] | |
11 | ||
12 | [simplesect Authors] | |
13 | ||
14 | * Peter Dimov | |
15 | ||
16 | [endsimplesect] | |
17 | ||
18 | [section Header <boost/core/typeinfo.hpp>] | |
19 | ||
20 | The header `<boost/core/typeinfo.hpp>` defines a class | |
21 | `boost::core::typeinfo`, which is an alias for `std::type_info` | |
22 | when RTTI is enabled, and is a reasonable substitute when RTTI | |
23 | is not supported. | |
24 | ||
25 | The macro `BOOST_CORE_TYPEID`, when applied to a type `T`, is the | |
26 | equivalent of `typeid(T)` and produces a reference to a const | |
27 | `typeinfo` object. | |
28 | ||
29 | The function `boost::core::demangled_name` takes a | |
30 | `boost::core::typeinfo const & ti` and either returns `ti.name()`, | |
31 | when that string doesn't need to be demangled, or | |
32 | `boost::core::demangle(ti.name())`, when it does. The return type | |
33 | of `boost::core::demangled_name` is `char const*` in the first case | |
34 | and `std::string` in the second. | |
35 | ||
36 | [section Synopsis] | |
37 | ||
38 | `` | |
39 | namespace boost | |
40 | { | |
41 | ||
42 | namespace core | |
43 | { | |
44 | class typeinfo; | |
45 | /* char const* or std::string */ demangled_name( typeinfo const & ti ); | |
46 | } | |
47 | ||
48 | } | |
49 | ||
50 | #define BOOST_CORE_TYPEID(T) /*unspecified*/ | |
51 | `` | |
52 | ||
53 | [endsect] | |
54 | ||
55 | [section Example] | |
56 | ||
57 | `` | |
58 | #include <boost/core/typeinfo.hpp> | |
59 | #include <iostream> | |
60 | ||
61 | template<class T1, class T2> struct X | |
62 | { | |
63 | }; | |
64 | ||
65 | int main() | |
66 | { | |
67 | typedef X<void const*, void(*)(float)> T; | |
68 | ||
69 | boost::core::typeinfo const & ti = BOOST_CORE_TYPEID(T); | |
70 | ||
71 | std::cout << boost::core::demangled_name( ti ) << std::endl; | |
72 | } | |
73 | `` | |
74 | ||
75 | [endsect] | |
76 | ||
77 | [endsect] | |
78 | ||
79 | [endsect] |