]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/container/throw_exception.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / container / throw_exception.hpp
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2012-2013. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // See http://www.boost.org/libs/container for documentation.
8 //
9 //////////////////////////////////////////////////////////////////////////////
10
11 #ifndef BOOST_CONTAINER_THROW_EXCEPTION_HPP
12 #define BOOST_CONTAINER_THROW_EXCEPTION_HPP
13
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
16 #endif
17
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
19 # pragma once
20 #endif
21
22 #include <boost/container/detail/config_begin.hpp>
23 #include <boost/container/detail/workaround.hpp>
24 #include <boost/core/ignore_unused.hpp>
25
26 #ifndef BOOST_NO_EXCEPTIONS
27 #include <exception> //for std exception base
28
29 # if defined(BOOST_CONTAINER_USE_STD_EXCEPTIONS)
30 #include <stdexcept> //for std::out_of_range, std::length_error, std::logic_error, std::runtime_error
31 #include <string> //for implicit std::string conversion
32 #include <new> //for std::bad_alloc
33
34 namespace boost {
35 namespace container {
36
37 typedef std::bad_alloc bad_alloc_t;
38 typedef std::out_of_range out_of_range_t;
39 typedef std::length_error length_error_t;
40 typedef std::logic_error logic_error_t;
41 typedef std::runtime_error runtime_error_t;
42
43 }} //namespace boost::container
44
45 # else //!BOOST_CONTAINER_USE_STD_EXCEPTIONS
46
47 namespace boost {
48 namespace container {
49
50 class BOOST_SYMBOL_VISIBLE exception
51 : public ::std::exception
52 {
53 typedef ::std::exception std_exception_t;
54
55 public:
56
57 //msg must be a static string (guaranteed by callers)
58 explicit exception(const char *msg)
59 : std_exception_t(), m_msg(msg)
60 {}
61
62 virtual const char *what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE
63 { return m_msg ? m_msg : "unknown boost::container exception"; }
64
65 private:
66 const char *m_msg;
67 };
68
69 class BOOST_SYMBOL_VISIBLE bad_alloc
70 : public exception
71 {
72 public:
73 bad_alloc()
74 : exception("boost::container::bad_alloc thrown")
75 {}
76 };
77
78 typedef bad_alloc bad_alloc_t;
79
80 class BOOST_SYMBOL_VISIBLE out_of_range
81 : public exception
82 {
83 public:
84 explicit out_of_range(const char *msg)
85 : exception(msg)
86 {}
87 };
88
89 typedef out_of_range out_of_range_t;
90
91 class BOOST_SYMBOL_VISIBLE length_error
92 : public exception
93 {
94 public:
95 explicit length_error(const char *msg)
96 : exception(msg)
97 {}
98 };
99
100 typedef out_of_range length_error_t;
101
102 class BOOST_SYMBOL_VISIBLE logic_error
103 : public exception
104 {
105 public:
106 explicit logic_error(const char *msg)
107 : exception(msg)
108 {}
109 };
110
111 typedef logic_error logic_error_t;
112
113 class BOOST_SYMBOL_VISIBLE runtime_error
114 : public exception
115 {
116 public:
117 explicit runtime_error(const char *msg)
118 : exception(msg)
119 {}
120 };
121
122 typedef runtime_error runtime_error_t;
123
124 } // namespace boost {
125 } // namespace container {
126
127 # endif
128 #else
129 #include <boost/assert.hpp>
130 #include <cstdlib> //for std::abort
131 #endif
132
133 namespace boost {
134 namespace container {
135
136 #if defined(BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS)
137 //The user must provide definitions for the following functions
138
139 BOOST_NORETURN void throw_bad_alloc();
140
141 BOOST_NORETURN void throw_out_of_range(const char* str);
142
143 BOOST_NORETURN void throw_length_error(const char* str);
144
145 BOOST_NORETURN void throw_logic_error(const char* str);
146
147 BOOST_NORETURN void throw_runtime_error(const char* str);
148
149 #elif defined(BOOST_NO_EXCEPTIONS)
150
151 BOOST_NORETURN inline void throw_bad_alloc()
152 {
153 BOOST_ASSERT(!"boost::container bad_alloc thrown");
154 std::abort();
155 }
156
157 BOOST_NORETURN inline void throw_out_of_range(const char* str)
158 {
159 boost::ignore_unused(str);
160 BOOST_ASSERT_MSG(!"boost::container out_of_range thrown", str);
161 std::abort();
162 }
163
164 BOOST_NORETURN inline void throw_length_error(const char* str)
165 {
166 boost::ignore_unused(str);
167 BOOST_ASSERT_MSG(!"boost::container length_error thrown", str);
168 std::abort();
169 }
170
171 BOOST_NORETURN inline void throw_logic_error(const char* str)
172 {
173 boost::ignore_unused(str);
174 BOOST_ASSERT_MSG(!"boost::container logic_error thrown", str);
175 std::abort();
176 }
177
178 BOOST_NORETURN inline void throw_runtime_error(const char* str)
179 {
180 boost::ignore_unused(str);
181 BOOST_ASSERT_MSG(!"boost::container runtime_error thrown", str);
182 std::abort();
183 }
184
185 #else //defined(BOOST_NO_EXCEPTIONS)
186
187 //! Exception callback called by Boost.Container when fails to allocate the requested storage space.
188 //! <ul>
189 //! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is NOT defined
190 //! <code>boost::container::bad_alloc(str)</code> is thrown.</li>
191 //!
192 //! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is defined
193 //! <code>std::bad_alloc(str)</code> is thrown.</li>
194 //!
195 //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
196 //! is NOT defined <code>BOOST_ASSERT(!"boost::container bad_alloc thrown")</code> is called
197 //! and <code>std::abort()</code> if the former returns.</li>
198 //!
199 //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
200 //! the user must provide an implementation and the function should not return.</li>
201 //! </ul>
202 BOOST_NORETURN inline void throw_bad_alloc()
203 {
204 throw bad_alloc_t();
205 }
206
207 //! Exception callback called by Boost.Container to signal arguments out of range.
208 //! <ul>
209 //! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is NOT defined
210 //! <code>boost::container::out_of_range(str)</code> is thrown.</li>
211 //!
212 //! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is defined
213 //! <code>std::out_of_range(str)</code> is thrown.</li>
214 //!
215 //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
216 //! is NOT defined <code>BOOST_ASSERT_MSG(!"boost::container out_of_range thrown", str)</code> is called
217 //! and <code>std::abort()</code> if the former returns.</li>
218 //!
219 //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
220 //! the user must provide an implementation and the function should not return.</li>
221 //! </ul>
222 BOOST_NORETURN inline void throw_out_of_range(const char* str)
223 {
224 throw out_of_range_t(str);
225 }
226
227 //! Exception callback called by Boost.Container to signal errors resizing.
228 //! <ul>
229 //!
230 //! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is NOT defined
231 //! <code>boost::container::length_error(str)</code> is thrown.</li>
232 //!
233 //! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is defined
234 //! <code>std::length_error(str)</code> is thrown.</li>
235 //!
236 //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
237 //! is NOT defined <code>BOOST_ASSERT_MSG(!"boost::container length_error thrown", str)</code> is called
238 //! and <code>std::abort()</code> if the former returns.</li>
239 //!
240 //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
241 //! the user must provide an implementation and the function should not return.</li>
242 //! </ul>
243 BOOST_NORETURN inline void throw_length_error(const char* str)
244 {
245 throw length_error_t(str);
246 }
247
248 //! Exception callback called by Boost.Container to report errors in the internal logical
249 //! of the program, such as violation of logical preconditions or class invariants.
250 //! <ul>
251 //!
252 //! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is NOT defined
253 //! <code>boost::container::logic_error(str)</code> is thrown.</li>
254 //!
255 //! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is defined
256 //! <code>std::logic_error(str)</code> is thrown.</li>
257 //!
258 //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
259 //! is NOT defined <code>BOOST_ASSERT_MSG(!"boost::container logic_error thrown", str)</code> is called
260 //! and <code>std::abort()</code> if the former returns.</li>
261 //!
262 //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
263 //! the user must provide an implementation and the function should not return.</li>
264 //! </ul>
265 BOOST_NORETURN inline void throw_logic_error(const char* str)
266 {
267 throw logic_error_t(str);
268 }
269
270 //! Exception callback called by Boost.Container to report errors that can only be detected during runtime.
271 //! <ul>
272 //! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is NOT defined
273 //! <code>boost::container::runtime_error(str)</code> is thrown.</li>
274 //!
275 //! <li>If BOOST_NO_EXCEPTIONS is NOT defined and BOOST_CONTAINER_USE_STD_EXCEPTIONS is defined
276 //! <code>std::runtime_error(str)</code> is thrown.</li>
277 //!
278 //! <li>If BOOST_NO_EXCEPTIONS is defined and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
279 //! is NOT defined <code>BOOST_ASSERT_MSG(!"boost::container runtime_error thrown", str)</code> is called
280 //! and <code>std::abort()</code> if the former returns.</li>
281 //!
282 //! <li>If BOOST_NO_EXCEPTIONS and BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS are defined
283 //! the user must provide an implementation and the function should not return.</li>
284 //! </ul>
285 BOOST_NORETURN inline void throw_runtime_error(const char* str)
286 {
287 throw runtime_error_t(str);
288 }
289
290 #endif
291
292 }} //namespace boost { namespace container {
293
294 #include <boost/container/detail/config_end.hpp>
295
296 #endif //#ifndef BOOST_CONTAINER_THROW_EXCEPTION_HPP