Ticket #1913: PATCH.null_deleter.diff
File PATCH.null_deleter.diff, 5.7 KB (added by , 10 years ago) |
---|
-
new file oost/smart_ptr/null_deleter.hpp
diff --git a/boost/smart_ptr/null_deleter.hpp b/boost/smart_ptr/null_deleter.hpp new file mode 100644 index 0000000..1fd2cfe
- + 1 #ifndef BOOST_SMART_PTR_NULL_DELETER_HPP_INCLUDED 2 #define BOOST_SMART_PTR_NULL_DELETER_HPP_INCLUDED 3 4 // 5 // null_deleter.hpp 6 // 7 // (C) Copyright 2004 Robert Ramey and Martin Ecker 8 // 9 // Distributed under the Boost Software License, Version 1.0. (See 10 // accompanying file LICENSE_1_0.txt or copy at 11 // http://www.boost.org/LICENSE_1_0.txt) 12 // 13 // See http://www.boost.org/libs/smart_ptr/null_deleter.htm for documentation. 14 // 15 16 namespace boost 17 { 18 19 // A deleter that does nothing, allows usage of shared_ptr with stack 20 // allocated or static objects. 21 // Taken from boost/serialization/shared_ptr.hpp 22 23 struct null_deleter 24 { 25 void operator()(void const *) const {} 26 }; 27 28 } // namespace boost 29 30 31 #endif // #ifndef BOOST_SMART_PTR_NULL_DELETER_HPP_INCLUDED -
new file libs/smart_ptr/null_deleter.htm
diff --git a/libs/smart_ptr/null_deleter.htm b/libs/smart_ptr/null_deleter.htm new file mode 100644 index 0000000..aead4ba
- + 1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> 2 <html> 3 <head> 4 <title>pointer_cast.hpp</title> 5 </head> 6 <body> 7 <h1><IMG height="86" alt="C++ Boost" src="../../boost.png" width="277" align="middle" border="0">Null Deleter</h1> 8 <H2><A name="synopsis">Synopsis</A></H2> 9 <P>A trivial deleter for use with <code>boost::shared_ptr<...></code> to make it possible to 10 have <code>boost::shared_ptr<...></code> "own" objects that are cleaned up by 11 some other mechanism (for example because they are created on the stack). 12 <BLOCKQUOTE> 13 <PRE> 14 namespace boost { 15 16 struct null_deleter 17 { 18 void operator()(void const *) const; 19 }; 20 21 } // namespace boost 22 </PRE> 23 </BLOCKQUOTE> 24 <hr> 25 <p>Revised: $Date$</p> 26 <p>Copyright 2004 Robert Ramey and Martin Ecker. Use, modification, and distribution are subject to 27 the Boost Software License, Version 1.0. (See accompanying file <A href="../../LICENSE_1_0.txt"> 28 LICENSE_1_0.txt</A> or a copy at <<A href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</A>>.)</p> 29 </body> 30 </html> -
libs/smart_ptr/smart_ptr.htm
diff --git a/libs/smart_ptr/smart_ptr.htm b/libs/smart_ptr/smart_ptr.htm index 92ad2be..9115740 100644
a b 72 72 </tr> 73 73 </table> 74 74 </div> 75 <p>A trivial deleter to allow use of <a href="shared_ptr.htm"><b>shared_ptr</b></a> with stack 76 allocated objects is provided as well:</p> 77 <div align="left"> 78 <table border="1" cellpadding="4" cellspacing="0"> 79 <tr> 80 <td><a href="null_deleter.htm"><b>null_deleter</b></a></td> 81 <td><a href="../../boost/smart_ptr/null_deleter.hpp"><boost/smart_ptr/null_deleter.hpp></a></td> 82 <td>No-op deleter for <code>shared_ptr</code>.</td> 83 </tr> 84 </table> 85 </div> 75 86 <p>A test program, <a href="test/smart_ptr_test.cpp">smart_ptr_test.cpp</a>, is 76 87 provided to verify correct operation.</p> 77 88 <p>A page on <a href="compatibility.htm">compatibility</a> with older versions of -
libs/smart_ptr/test/Jamfile.v2
diff --git a/libs/smart_ptr/test/Jamfile.v2 b/libs/smart_ptr/test/Jamfile.v2 index 66d8007..16ce659 100644
a b import testing ; 69 69 [ run get_deleter_array_test.cpp ] 70 70 [ run ip_hash_test.cpp ] 71 71 [ run owner_less_test.cpp ] 72 [ run null_deleter_test.cpp ] 72 73 ; 73 74 } -
new file libs/smart_ptr/test/null_deleter_test.cpp
diff --git a/libs/smart_ptr/test/null_deleter_test.cpp b/libs/smart_ptr/test/null_deleter_test.cpp new file mode 100644 index 0000000..2fc8060
- + 1 #include <boost/config.hpp> 2 3 // 4 // null_deleter_test.cpp 5 // 6 // Copyright (c) 2012 Carsten Neumann 7 // 8 // Distributed under the Boost Software License, Version 1.0. (See 9 // accompanying file LICENSE_1_0.txt or copy at 10 // http://www.boost.org/LICENSE_1_0.txt) 11 // 12 13 #include <boost/detail/lightweight_test.hpp> 14 15 #include <boost/smart_ptr/null_deleter.hpp> 16 #include <boost/shared_ptr.hpp> 17 #include <boost/weak_ptr.hpp> 18 19 int ctor_count = 0; 20 int dtor_count = 0; 21 22 class A 23 { 24 public: 25 A(void) 26 { 27 ++ctor_count; 28 } 29 30 ~A(void) 31 { 32 ++dtor_count; 33 } 34 35 int dummy; 36 }; 37 38 int main(int, char* argv[]) 39 { 40 { 41 // reset counts 42 ctor_count = 0; 43 dtor_count = 0; 44 45 A a0; 46 47 { 48 boost::shared_ptr<A> sp(&a0, boost::null_deleter()); 49 BOOST_TEST(sp.use_count() == 1); 50 BOOST_TEST(ctor_count == 1); 51 BOOST_TEST(dtor_count == 0); 52 } 53 54 BOOST_TEST(ctor_count == 1); 55 BOOST_TEST(dtor_count == 0); 56 } 57 58 BOOST_TEST(ctor_count == 1); 59 BOOST_TEST(dtor_count == 1); 60 61 { 62 // reset counts 63 ctor_count = 0; 64 dtor_count = 0; 65 66 A a0; 67 boost::shared_ptr<A> sp0(&a0, boost::null_deleter()); 68 boost::shared_ptr<A> sp1(sp0); 69 70 BOOST_TEST(sp0.use_count() == 2); 71 BOOST_TEST(ctor_count == 1); 72 BOOST_TEST(dtor_count == 0); 73 74 sp0.reset(); 75 BOOST_TEST(ctor_count == 1); 76 BOOST_TEST(dtor_count == 0); 77 78 sp1.reset(); 79 BOOST_TEST(ctor_count == 1); 80 BOOST_TEST(dtor_count == 0); 81 } 82 83 BOOST_TEST(ctor_count == 1); 84 BOOST_TEST(dtor_count == 1); 85 86 return boost::report_errors(); 87 }