]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_index/examples/registry.cpp
1 // Copyright 2013-2022 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>.)
7 //[type_index_registry_example
9 The following example shows how an information about a type could be stored.
10 Example works with and without RTTI.
13 #include <boost/type_index.hpp>
14 #include <boost/unordered/unordered_set.hpp>
16 // Making `#include <cassert>` visible in docs, while actually using `BOOST_TEST`
17 // instead of `assert`. This is required to verify correct behavior even if NDEBUG
18 // is defined and to avoid `unused local variable` warnings with defined NDEBUG.
21 #include <boost/core/lightweight_test.hpp>
25 #define assert(X) BOOST_TEST(X)
26 /* !Comment block is not closed intentionaly!
30 !Closing comment block! */
34 boost::unordered_set
<boost::typeindex::type_index
> types
;
36 // Storing some `boost::type_info`s
37 types
.insert(boost::typeindex::type_id
<int>());
38 types
.insert(boost::typeindex::type_id
<float>());
40 // `types` variable contains two `boost::type_index`es:
41 assert(types
.size() == 2);
43 // Const, volatile and reference will be striped from the type:
44 bool is_inserted
= types
.insert(boost::typeindex::type_id
<const int>()).second
;
46 assert(types
.erase(boost::typeindex::type_id
<float&>()) == 1);
48 // We have erased the `float` type, only `int` remains
49 assert(*types
.begin() == boost::typeindex::type_id
<int>());
51 return boost::report_errors();
55 //] [/type_index_registry_example]