]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_index/examples/user_defined_typeinfo.cpp
1 // Copyright 2013-2020 Antony Polukhin
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>.)
8 //[type_index_my_type_index_worldwide_macro
10 There is an easy way to force `boost::typeindex::type_id` to use your own type_index class.
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:
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]
21 #include <boost/core/lightweight_test.hpp>
25 #define assert(X) BOOST_TEST(X)
28 using namespace my_namespace
;
31 //[type_index_my_type_index_usage
33 Finally we can use the my_type_index class for getting type indexes:
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
>()
45 assert(vec
.pretty_name() == "my_classes");
46 assert(cl1
.pretty_name() == "my_class");
48 //] [/type_index_my_type_index_usage]
50 //[type_index_my_type_index_type_id_runtime_test
52 Now the following example will compile and work.
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]
59 //[type_index_my_type_index_worldwide_usage
61 That's it! Now all TypeIndex global methods and typedefs will be using your class:
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]
68 return boost::report_errors();