| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | #ifndef BOOST_CHECKED_DELETE_HPP_INCLUDED
 | 
					
						
							|  |  |  | #define BOOST_CHECKED_DELETE_HPP_INCLUDED
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-11-28 15:35:21 +00:00
										 |  |  | // MS compatible compilers support #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 17:09:24 +00:00
										 |  |  | #if defined(_MSC_VER) && (_MSC_VER >= 1020)
 | 
					
						
							|  |  |  | # pragma once
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  boost/checked_delete.hpp
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2003-02-14 16:20:01 +00:00
										 |  |  | //  Copyright (c) 2002, 2003 Peter Dimov
 | 
					
						
							| 
									
										
										
										
											2003-08-16 01:05:43 +00:00
										 |  |  | //  Copyright (c) 2003 Daniel Frey
 | 
					
						
							|  |  |  | //  Copyright (c) 2003 Howard Hinnant
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2004-08-12 17:13:07 +00:00
										 |  |  | //  Distributed under the Boost Software License, Version 1.0. (See
 | 
					
						
							|  |  |  | //  accompanying file LICENSE_1_0.txt or copy at
 | 
					
						
							|  |  |  | //  http://www.boost.org/LICENSE_1_0.txt)
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2002-12-23 02:43:12 +00:00
										 |  |  | //  See http://www.boost.org/libs/utility/checked_delete.html for documentation.
 | 
					
						
							| 
									
										
										
										
											2002-11-14 14:53:32 +00:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace boost | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // verify that types are complete for increased safety
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  | template<class T> inline void checked_delete(T * x) | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-08-16 01:05:43 +00:00
										 |  |  |     // intentionally complex - simplification causes regressions
 | 
					
						
							| 
									
										
										
										
											2003-07-16 10:53:06 +00:00
										 |  |  |     typedef char type_must_be_complete[ sizeof(T)? 1: -1 ]; | 
					
						
							| 
									
										
										
										
											2003-08-16 01:05:43 +00:00
										 |  |  |     (void) sizeof(type_must_be_complete); | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     delete x; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-23 13:55:18 +00:00
										 |  |  | template<class T> inline void checked_array_delete(T * x) | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-07-16 10:53:06 +00:00
										 |  |  |     typedef char type_must_be_complete[ sizeof(T)? 1: -1 ]; | 
					
						
							| 
									
										
										
										
											2003-08-16 01:05:43 +00:00
										 |  |  |     (void) sizeof(type_must_be_complete); | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     delete [] x; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class T> struct checked_deleter | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     typedef void result_type; | 
					
						
							|  |  |  |     typedef T * argument_type; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-02-14 16:20:01 +00:00
										 |  |  |     void operator()(T * x) const | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2003-07-16 10:53:06 +00:00
										 |  |  |         // boost:: disables ADL
 | 
					
						
							| 
									
										
										
										
											2003-02-25 13:00:22 +00:00
										 |  |  |         boost::checked_delete(x); | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class T> struct checked_array_deleter | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     typedef void result_type; | 
					
						
							|  |  |  |     typedef T * argument_type; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-02-14 16:20:01 +00:00
										 |  |  |     void operator()(T * x) const | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2003-02-25 13:00:22 +00:00
										 |  |  |         boost::checked_array_delete(x); | 
					
						
							| 
									
										
										
										
											2002-01-22 13:38:52 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // namespace boost
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif  // #ifndef BOOST_CHECKED_DELETE_HPP_INCLUDED
 |