// Copyright 2013-2015 Antony Polukhin // Distributed under the Boost Software License, Version 1.0. // (See the accompanying file LICENSE_1_0.txt // or a copy at .) //[type_index_my_type_index_worldwide_macro /*` There is an easy way to force `boost::typeindex::type_id` to use your own type_index class. All we need to do is just define `BOOST_TYPE_INDEX_USER_TYPEINDEX` to the full path to header file of your type index class: */ // BOOST_TYPE_INDEX_USER_TYPEINDEX must be defined *BEFORE* first inclusion of #define BOOST_TYPE_INDEX_USER_TYPEINDEX #include //] [/type_index_my_type_index_worldwide_macro] #include #ifdef assert # undef assert #endif #define assert(X) BOOST_TEST(X) using namespace my_namespace; int main() { //[type_index_my_type_index_usage /*` Finally we can use the my_type_index class for getting type indexes: */ my_type_index cl1 = my_type_index::type_id(), st1 = my_type_index::type_id(), st2 = my_type_index::type_id(), vec = my_type_index::type_id() ; assert(cl1 != st1); assert(st2 == st1); assert(vec.pretty_name() == "my_classes"); assert(cl1.pretty_name() == "my_class"); //] [/type_index_my_type_index_usage] //[type_index_my_type_index_type_id_runtime_test /*` Now the following example will compile and work. */ my_struct str; my_class& reference = str; assert(my_type_index::type_id() == my_type_index::type_id_runtime(reference)); //][/type_index_my_type_index_type_id_runtime_test] //[type_index_my_type_index_worldwide_usage /*` That's it! Now all TypeIndex global methods and typedefs will be using your class: */ boost::typeindex::type_index worldwide = boost::typeindex::type_id(); assert(worldwide.pretty_name() == "my_classes"); assert(worldwide == my_type_index::type_id()); //][/type_index_my_type_index_worldwide_usage] }