blob: 9b3643e05232c65dc28dbc0a64996b5afd5ac46f [file] [log] [blame]
Brian Silverman87d3c952018-08-05 00:08:45 -07001From 8f57d59bfbc978673a2493a90b4f3e7e54ddbf18 Mon Sep 17 00:00:00 2001
2From: Antony Polukhin <antoshkka@gmail.com>
3Date: Thu, 20 Feb 2014 18:30:11 +0400
4Subject: [PATCH] Boost.Exception now uses TypeIndex to reduce duplicate code
5 and simplify name demanglings
6
7---
8 include/boost/exception/detail/type_info.hpp | 43 +++-------------------
9 include/boost/exception/diagnostic_information.hpp | 2 +-
10 include/boost/exception/exception.hpp | 3 +-
11 include/boost/exception/info.hpp | 2 +-
12 test/Jamfile.v2 | 2 +
13 5 files changed, 12 insertions(+), 40 deletions(-)
14
15diff --git a/include/boost/exception/detail/type_info.hpp b/include/boost/exception/detail/type_info.hpp
16index 6e5942d..a247b71 100644
17--- a/include/boost/exception/detail/type_info.hpp
18+++ b/include/boost/exception/detail/type_info.hpp
19@@ -12,13 +12,7 @@
20 #pragma warning(push,1)
21 #endif
22
23-#include <boost/detail/sp_typeinfo.hpp>
24-#include <boost/current_function.hpp>
25-#include <boost/config.hpp>
26-//#ifndef BOOST_NO_TYPEID
27-//#include <boost/units/detail/utility.hpp>
28-//#endif
29-#include <string>
30+#include <boost/type_index.hpp>
31
32 namespace
33 boost
34@@ -28,11 +22,7 @@ boost
35 std::string
36 tag_type_name()
37 {
38-#ifdef BOOST_NO_TYPEID
39- return BOOST_CURRENT_FUNCTION;
40-#else
41- return /*units::detail::demangle*/(typeid(T*).name());
42-#endif
43+ return boost::typeind::type_id<T*>().pretty_name();
44 }
45
46 template <class T>
47@@ -40,41 +30,20 @@ boost
48 std::string
49 type_name()
50 {
51-#ifdef BOOST_NO_TYPEID
52- return BOOST_CURRENT_FUNCTION;
53-#else
54- return /*units::detail::demangle*/(typeid(T).name());
55-#endif
56+ return boost::typeind::type_id<T>().pretty_name();
57 }
58
59 namespace
60 exception_detail
61 {
62- struct
63- type_info_
64- {
65- detail::sp_typeinfo const * type_;
66-
67- explicit
68- type_info_( detail::sp_typeinfo const & type ):
69- type_(&type)
70- {
71- }
72-
73- friend
74- bool
75- operator<( type_info_ const & a, type_info_ const & b )
76- {
77- return 0!=(a.type_->before(*b.type_));
78- }
79- };
80+ typedef boost::typeind::type_index type_info_;
81 }
82 }
83
84-#define BOOST_EXCEPTION_STATIC_TYPEID(T) ::boost::exception_detail::type_info_(BOOST_SP_TYPEID(T))
85+#define BOOST_EXCEPTION_STATIC_TYPEID(T) ::boost::typeind::type_id<T>()
86
87 #ifndef BOOST_NO_RTTI
88-#define BOOST_EXCEPTION_DYNAMIC_TYPEID(x) ::boost::exception_detail::type_info_(typeid(x))
89+#define BOOST_EXCEPTION_DYNAMIC_TYPEID(x) ::boost::typeind::type_id_runtime(x)
90 #endif
91
92 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
93diff --git a/include/boost/exception/diagnostic_information.hpp b/include/boost/exception/diagnostic_information.hpp
94index 2f5cb88..0f8b5e8 100644
95--- a/include/boost/exception/diagnostic_information.hpp
96+++ b/include/boost/exception/diagnostic_information.hpp
97@@ -151,7 +151,7 @@ boost
98 #ifndef BOOST_NO_RTTI
99 if ( verbose )
100 tmp << std::string("Dynamic exception type: ") <<
101- /*units::detail::demangle*/((be?(BOOST_EXCEPTION_DYNAMIC_TYPEID(*be)):(BOOST_EXCEPTION_DYNAMIC_TYPEID(*se))).type_->name()) << '\n';
102+ /*units::detail::demangle*/((be?(BOOST_EXCEPTION_DYNAMIC_TYPEID(*be)):(BOOST_EXCEPTION_DYNAMIC_TYPEID(*se)))) << '\n';
103 #endif
104 if( with_what && se && verbose )
105 tmp << "std::exception::what: " << wh << '\n';
106diff --git a/include/boost/exception/exception.hpp b/include/boost/exception/exception.hpp
107index 9f20a04..53c341f 100644
108--- a/include/boost/exception/exception.hpp
109+++ b/include/boost/exception/exception.hpp
110@@ -12,6 +12,8 @@
111 #pragma warning(push,1)
112 #endif
113
114+#include <boost/exception/detail/type_info.hpp>
115+
116 namespace
117 boost
118 {
119@@ -151,7 +153,6 @@ boost
120 exception_detail
121 {
122 class error_info_base;
123- struct type_info_;
124
125 struct
126 error_info_container
127diff --git a/include/boost/exception/info.hpp b/include/boost/exception/info.hpp
128index edbf058..e0f4950 100644
129--- a/include/boost/exception/info.hpp
130+++ b/include/boost/exception/info.hpp
131@@ -96,7 +96,7 @@ boost
132 {
133 shared_ptr<error_info_base> const & p = i->second;
134 #ifndef BOOST_NO_RTTI
135- BOOST_ASSERT( *BOOST_EXCEPTION_DYNAMIC_TYPEID(*p).type_==*ti.type_ );
136+ BOOST_ASSERT(BOOST_EXCEPTION_DYNAMIC_TYPEID(*p)==ti );
137 #endif
138 return p;
139 }
140diff --git a/test/Jamfile.v2 b/test/Jamfile.v2
141index d2dfcd6..5bd076d 100644
142--- a/test/Jamfile.v2
143+++ b/test/Jamfile.v2
144@@ -35,7 +35,9 @@ run enable_error_info_test.cpp helper1.cpp ;
145 run throw_exception_test.cpp helper2.cpp ;
146 run errno_test.cpp ;
147 run error_info_test.cpp ;
148+run error_info_test.cpp : : : <rtti>off : error_info_test_rtti ;
149 run diagnostic_information_test.cpp ;
150+run diagnostic_information_test.cpp : : : <rtti>off : diagnostic_information_test_rtti ;
151 run refcount_ptr_test.cpp ;
152 run current_exception_cast_test.cpp ;
153 run no_exceptions_test.cpp : : : <exception-handling>off ;
154--
1551.8.5.3
156