// 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_registry_example /*` The following example shows how an information about a type could be stored. Example works with and without RTTI. */ #include #include #include //<- // Making `#include ` visible in docs, while actually using `BOOST_TEST` // instead of `assert`. This is required to verify correct behavior even if NDEBUG // is defined and to avoid `unused local variable` warnings with defined NDEBUG. #include #ifdef assert # undef assert #endif #define assert(X) BOOST_TEST(X) /* !Comment block is not closed intentionaly! //-> #include //<- !Closing comment block! */ //-> int main() { boost::unordered_set types; // Storing some `boost::type_info`s types.insert(boost::typeindex::type_id()); types.insert(boost::typeindex::type_id()); // `types` variable contains two `boost::type_index`es: assert(types.size() == 2); // Const, volatile and reference will be striped from the type: bool is_inserted = types.insert(boost::typeindex::type_id()).second; assert(!is_inserted); assert(types.erase(boost::typeindex::type_id()) == 1); // We have erased the `float` type, only `int` remains assert(*types.begin() == boost::typeindex::type_id()); } //] [/type_index_registry_example]