diff --git a/doc/type_index.qbk b/doc/type_index.qbk index fc24a70..50c96a3 100644 --- a/doc/type_index.qbk +++ b/doc/type_index.qbk @@ -199,6 +199,9 @@ Issues with cross module type comparison on a bugged compilers are bypassed by d [import ../examples/exact_types_match.cpp] [section Exact type match: storing type with const, volatile and reference ] [type_index_exact_type_match_example] [endsect] +[import ../examples/table_of_names.cpp] +[section Table of raw_name() and pretty_name() outputs with and without RTTI ] [type_index_names_table] [endsect] + [endsect] [xinclude autodoc.xml] diff --git a/examples/table_of_names.cpp b/examples/table_of_names.cpp new file mode 100644 index 0000000..6880ce2 --- /dev/null +++ b/examples/table_of_names.cpp @@ -0,0 +1,90 @@ +// Copyright 2013-2014 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_names_table +/*` + The following example shows how different type names look when we explicitly use classes for RTTI and RTT off. + + This example requires RTTI. For a more portable example see 'Getting human readable and mangled type names': +*/ + + +#include +#include +#include + +template +void print(const char* name) { + boost::typeindex::stl_type_index sti = boost::typeindex::stl_type_index::type_id(); + boost::typeindex::ctti_type_index cti = boost::typeindex::ctti_type_index::type_id(); + std::cout << "\t[" /* start of the row */ + << "[" << name << "]" + << "[`" << sti.raw_name() << "`] " + << "[`" << sti.pretty_name() << "`] " + << "[`" << cti.raw_name() << "`] " + << "]\n" /* end of the row */ ; +} + +struct user_defined_type{}; + +namespace ns1 { namespace ns2 { + struct user_defined_type{}; +}} // namespace ns1::ns2 + +namespace { + struct in_anon_type{}; +} // anonymous namespace + +namespace ns3 { namespace { namespace ns4 { + struct in_anon_type{}; +}}} // namespace ns3::{anonymous}::ns4 + + +template +class templ {}; + +template <> +class templ {}; + +int main() { + std::cout << "[table:id Table of names\n"; + std::cout << "\t[[Type] [RTTI & raw_name] [RTTI & pretty_name] [noRTTI & raw_name]]\n"; + + print("User defined type"); + print("In anonymous namespace"); + print("In ns3::{anonymous}::ns4 namespace"); + print >("Template class"); + print >("Template class (full specialization)"); + print, + templ + > >("Template class with templae classes"); + + + std::cout << "]\n"; +} + +/*` + Code from the example will produce the following table: + + [table:id Table of names + [[Type] [RTTI & raw_name] [RTTI & pretty_name] [noRTTI & raw_name]] + [[User defined type][`17user_defined_type`] [`user_defined_type`] [`user_defined_type]`] ] + [[In anonymous namespace][`N12_GLOBAL__N_112in_anon_typeE`] [`(anonymous namespace)::in_anon_type`] [`{anonymous}::in_anon_type]`] ] + [[In ns3::{anonymous}::ns4 namespace][`N3ns312_GLOBAL__N_13ns412in_anon_typeE`] [`ns3::(anonymous namespace)::ns4::in_anon_type`] [`ns3::{anonymous}::ns4::in_anon_type]`] ] + [[Template class][`5templIsiE`] [`templ`] [`templ]`] ] + [[Template class (full specialization)][`5templIiiE`] [`templ`] [`templ]`] ] + [[Template class with templae classes][`5templIS_IcaES_Ii17user_defined_typeEE`] [`templ, templ >`] [`templ, templ >]`] ] + ] + + We have not show the "noRTTI & pretty_name" column in the table becuse it is almost equal + to "noRTTI & raw_name" column. + + [warning With RTTI off different classes with same names in anonymous namespace may collapse. See 'RTTI emulation limitations'. ] +*/ + +//] [/type_index_names_table] diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index c87713e..9553aec 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -62,8 +62,11 @@ for local p in [ glob ../examples/*.cpp ] # RTTI on type_index += [ run $(p) ] ; - # RTTI off - local target_name = $(p[1]:B)_no_rtti ; - type_index += [ run $(p) : : : off : $(target_name) ] ; + if $(p) != ../examples/table_of_names.cpp + { + # RTTI off + local target_name = $(p[1]:B)_no_rtti ; + type_index += [ run $(p) : : : off : $(target_name) ] ; + } }