]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_index/examples/table_of_names.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_names_table
10 The following example shows how different type names look when we explicitly use classes for RTTI and RTT off.
12 This example requires RTTI. For a more portable example see 'Getting human readable and mangled type names':
16 #include <boost/type_index/stl_type_index.hpp>
17 #include <boost/type_index/ctti_type_index.hpp>
21 void print ( const char * name
) {
22 boost :: typeindex :: stl_type_index sti
= boost :: typeindex :: stl_type_index :: type_id
< T
>();
23 boost :: typeindex :: ctti_type_index cti
= boost :: typeindex :: ctti_type_index :: type_id
< T
>();
24 std :: cout
<< " \t [" /* start of the row */
26 << "[`" << sti
. raw_name () << "`] "
27 << "[`" << sti
. pretty_name () << "`] "
28 << "[`" << cti
. raw_name () << "`] "
29 << "] \n " /* end of the row */ ;
32 struct user_defined_type
{};
34 namespace ns1
{ namespace ns2
{
35 struct user_defined_type
{};
36 }} // namespace ns1::ns2
39 struct in_anon_type
{};
40 } // anonymous namespace
42 namespace ns3
{ namespace { namespace ns4
{
43 struct in_anon_type
{};
44 }}} // namespace ns3::{anonymous}::ns4
47 template < class T0
, class T1
>
51 class templ
< int , int > {};
54 std :: cout
<< "[table:id Table of names \n " ;
55 std :: cout
<< " \t [[Type] [RTTI & raw_name] [RTTI & pretty_name] [noRTTI & raw_name]] \n " ;
57 print
< user_defined_type
>( "User defined type" );
58 print
< in_anon_type
>( "In anonymous namespace" );
59 print
< ns3 :: ns4 :: in_anon_type
>( "In ns3::{anonymous}::ns4 namespace" );
60 print
< templ
< short , int > >( "Template class" );
61 print
< templ
< int , int > >( "Template class (full specialization)" );
63 templ
< char , signed char >,
64 templ
< int , user_defined_type
>
65 > >( "Template class with templae classes" );
72 Code from the example will produce the following table:
74 [table:id Table of names
75 [[Type] [RTTI & raw_name] [RTTI & pretty_name] [noRTTI & raw_name]]
76 [[User defined type][`17user_defined_type`] [`user_defined_type`] [`user_defined_type]`] ]
77 [[In anonymous namespace][`N12_GLOBAL__N_112in_anon_typeE`] [`(anonymous namespace)::in_anon_type`] [`{anonymous}::in_anon_type]`] ]
78 [[In ns3::{anonymous}::ns4 namespace][`N3ns312_GLOBAL__N_13ns412in_anon_typeE`] [`ns3::(anonymous namespace)::ns4::in_anon_type`] [`ns3::{anonymous}::ns4::in_anon_type]`] ]
79 [[Template class][`5templIsiE`] [`templ<short, int>`] [`templ<short int, int>]`] ]
80 [[Template class (full specialization)][`5templIiiE`] [`templ<int, int>`] [`templ<int, int>]`] ]
81 [[Template class with template classes][`5templIS_IcaES_Ii17user_defined_typeEE`] [`templ<templ<char, signed char>, templ<int, user_defined_type> >`] [`templ<templ<char, signed char>, templ<int, user_defined_type> >]`] ]
84 We have not show the "noRTTI & pretty_name" column in the table because it is almost equal
85 to "noRTTI & raw_name" column.
87 [warning With RTTI off different classes with same names in anonymous namespace may collapse. See 'RTTI emulation limitations'. ]
90 //] [/type_index_names_table]