]>
Commit | Line | Data |
---|---|---|
f67539c2 | 1 | // Copyright 2013-2020 Antony Polukhin |
7c673cae FG |
2 | |
3 | // Distributed under the Boost Software License, Version 1.0. | |
4 | // (See the accompanying file LICENSE_1_0.txt | |
5 | // or a copy at <http://www.boost.org/LICENSE_1_0.txt>.) | |
6 | ||
7 | ||
8 | //[type_index_my_type_index_worldwide_macro | |
9 | /*` | |
10 | There is an easy way to force `boost::typeindex::type_id` to use your own type_index class. | |
11 | ||
12 | All we need to do is just define `BOOST_TYPE_INDEX_USER_TYPEINDEX` to the full path to header file | |
13 | of your type index class: | |
14 | */ | |
15 | ||
16 | // BOOST_TYPE_INDEX_USER_TYPEINDEX must be defined *BEFORE* first inclusion of <boost/type_index.hpp> | |
17 | #define BOOST_TYPE_INDEX_USER_TYPEINDEX <boost/../libs/type_index/examples/user_defined_typeinfo.hpp> | |
18 | #include <boost/type_index.hpp> | |
19 | //] [/type_index_my_type_index_worldwide_macro] | |
20 | ||
21 | #include <boost/core/lightweight_test.hpp> | |
22 | #ifdef assert | |
23 | # undef assert | |
24 | #endif | |
25 | #define assert(X) BOOST_TEST(X) | |
26 | ||
27 | ||
28 | using namespace my_namespace; | |
29 | ||
30 | int main() { | |
31 | //[type_index_my_type_index_usage | |
32 | /*` | |
33 | Finally we can use the my_type_index class for getting type indexes: | |
34 | */ | |
35 | ||
36 | my_type_index | |
37 | cl1 = my_type_index::type_id<my_class>(), | |
38 | st1 = my_type_index::type_id<my_struct>(), | |
39 | st2 = my_type_index::type_id<my_struct>(), | |
40 | vec = my_type_index::type_id<my_classes>() | |
41 | ; | |
42 | ||
43 | assert(cl1 != st1); | |
44 | assert(st2 == st1); | |
45 | assert(vec.pretty_name() == "my_classes"); | |
46 | assert(cl1.pretty_name() == "my_class"); | |
47 | ||
48 | //] [/type_index_my_type_index_usage] | |
49 | ||
50 | //[type_index_my_type_index_type_id_runtime_test | |
51 | /*` | |
52 | Now the following example will compile and work. | |
53 | */ | |
54 | my_struct str; | |
55 | my_class& reference = str; | |
56 | assert(my_type_index::type_id<my_struct>() == my_type_index::type_id_runtime(reference)); | |
57 | //][/type_index_my_type_index_type_id_runtime_test] | |
58 | ||
59 | //[type_index_my_type_index_worldwide_usage | |
60 | /*` | |
61 | That's it! Now all TypeIndex global methods and typedefs will be using your class: | |
62 | */ | |
63 | boost::typeindex::type_index worldwide = boost::typeindex::type_id<my_classes>(); | |
64 | assert(worldwide.pretty_name() == "my_classes"); | |
65 | assert(worldwide == my_type_index::type_id<my_classes>()); | |
66 | //][/type_index_my_type_index_worldwide_usage] | |
92f5a8d4 TL |
67 | //<- |
68 | return boost::report_errors(); | |
69 | //-> | |
7c673cae FG |
70 | } |
71 | ||
72 |