]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_index/examples/registry.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / type_index / examples / registry.cpp
1 // Copyright 2013-2022 Antony Polukhin
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 //[type_index_registry_example
8 /*`
9 The following example shows how an information about a type could be stored.
10 Example works with and without RTTI.
11 */
12
13 #include <boost/type_index.hpp>
14 #include <boost/unordered/unordered_set.hpp>
15 //<-
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.
19 //
20 // boost-no-inspect
21 #include <boost/core/lightweight_test.hpp>
22 #ifdef assert
23 # undef assert
24 #endif
25 #define assert(X) BOOST_TEST(X)
26 /* !Comment block is not closed intentionaly!
27 //->
28 #include <cassert>
29 //<-
30 !Closing comment block! */
31 //->
32
33 int main() {
34 boost::unordered_set<boost::typeindex::type_index> types;
35
36 // Storing some `boost::type_info`s
37 types.insert(boost::typeindex::type_id<int>());
38 types.insert(boost::typeindex::type_id<float>());
39
40 // `types` variable contains two `boost::type_index`es:
41 assert(types.size() == 2);
42
43 // Const, volatile and reference will be striped from the type:
44 bool is_inserted = types.insert(boost::typeindex::type_id<const int>()).second;
45 assert(!is_inserted);
46 assert(types.erase(boost::typeindex::type_id<float&>()) == 1);
47
48 // We have erased the `float` type, only `int` remains
49 assert(*types.begin() == boost::typeindex::type_id<int>());
50 //<-
51 return boost::report_errors();
52 //->
53 }
54
55 //] [/type_index_registry_example]