|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r75390 - in trunk: boost/smart_ptr libs/smart_ptr/test
From: pdimov_at_[hidden]
Date: 2011-11-07 13:19:25
Author: pdimov
Date: 2011-11-07 13:19:24 EST (Mon, 07 Nov 2011)
New Revision: 75390
URL: http://svn.boost.org/trac/boost/changeset/75390
Log:
Add get_deleter for shared_array. Refs #4493.
Added:
trunk/libs/smart_ptr/test/get_deleter_array_test.cpp (contents, props changed)
Text files modified:
trunk/boost/smart_ptr/shared_array.hpp | 10 ++++++++++
trunk/libs/smart_ptr/test/Jamfile.v2 | 1 +
2 files changed, 11 insertions(+), 0 deletions(-)
Modified: trunk/boost/smart_ptr/shared_array.hpp
==============================================================================
--- trunk/boost/smart_ptr/shared_array.hpp (original)
+++ trunk/boost/smart_ptr/shared_array.hpp 2011-11-07 13:19:24 EST (Mon, 07 Nov 2011)
@@ -131,6 +131,11 @@
pn.swap(other.pn);
}
+ void * _internal_get_deleter( boost::detail::sp_typeinfo const & ti ) const
+ {
+ return pn.get_deleter( ti );
+ }
+
private:
T * px; // contained pointer
@@ -158,6 +163,11 @@
a.swap(b);
}
+template< class D, class T > D * get_deleter( shared_array<T> const & p )
+{
+ return static_cast< D * >( p._internal_get_deleter( BOOST_SP_TYPEID(D) ) );
+}
+
} // namespace boost
#endif // #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)
Modified: trunk/libs/smart_ptr/test/Jamfile.v2
==============================================================================
--- trunk/libs/smart_ptr/test/Jamfile.v2 (original)
+++ trunk/libs/smart_ptr/test/Jamfile.v2 2011-11-07 13:19:24 EST (Mon, 07 Nov 2011)
@@ -66,5 +66,6 @@
[ run sp_typeinfo_test.cpp ]
[ compile make_shared_fp_test.cpp ]
[ run sp_hash_test.cpp ]
+ [ run get_deleter_array_test.cpp ]
;
}
Added: trunk/libs/smart_ptr/test/get_deleter_array_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/smart_ptr/test/get_deleter_array_test.cpp 2011-11-07 13:19:24 EST (Mon, 07 Nov 2011)
@@ -0,0 +1,95 @@
+//
+// get_deleter_array_test.cpp
+//
+// Copyright (c) 2002, 2011 Peter Dimov
+//
+// 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)
+//
+
+#include <boost/shared_array.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+struct deleter
+{
+ int data;
+
+ deleter(): data(0)
+ {
+ }
+
+ void operator()(void *)
+ {
+ BOOST_TEST(data == 17041);
+ }
+};
+
+struct deleter2
+{
+};
+
+struct X
+{
+};
+
+int main()
+{
+ {
+ boost::shared_array<X> p;
+
+ BOOST_TEST(boost::get_deleter<void>(p) == 0);
+ BOOST_TEST(boost::get_deleter<void const>(p) == 0);
+ BOOST_TEST(boost::get_deleter<int>(p) == 0);
+ BOOST_TEST(boost::get_deleter<int const>(p) == 0);
+ BOOST_TEST(boost::get_deleter<X>(p) == 0);
+ BOOST_TEST(boost::get_deleter<X const>(p) == 0);
+ BOOST_TEST(boost::get_deleter<deleter>(p) == 0);
+ BOOST_TEST(boost::get_deleter<deleter const>(p) == 0);
+ BOOST_TEST(boost::get_deleter<deleter2>(p) == 0);
+ BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0);
+ }
+
+ {
+ boost::shared_array<X> p(new X[1]);
+
+ BOOST_TEST(boost::get_deleter<void>(p) == 0);
+ BOOST_TEST(boost::get_deleter<void const>(p) == 0);
+ BOOST_TEST(boost::get_deleter<int>(p) == 0);
+ BOOST_TEST(boost::get_deleter<int const>(p) == 0);
+ BOOST_TEST(boost::get_deleter<X>(p) == 0);
+ BOOST_TEST(boost::get_deleter<X const>(p) == 0);
+ BOOST_TEST(boost::get_deleter<deleter>(p) == 0);
+ BOOST_TEST(boost::get_deleter<deleter const>(p) == 0);
+ BOOST_TEST(boost::get_deleter<deleter2>(p) == 0);
+ BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0);
+ }
+
+ {
+ X x[1];
+ boost::shared_array<X> p(x, deleter());
+
+ BOOST_TEST(boost::get_deleter<void>(p) == 0);
+ BOOST_TEST(boost::get_deleter<void const>(p) == 0);
+ BOOST_TEST(boost::get_deleter<int>(p) == 0);
+ BOOST_TEST(boost::get_deleter<int const>(p) == 0);
+ BOOST_TEST(boost::get_deleter<X>(p) == 0);
+ BOOST_TEST(boost::get_deleter<X const>(p) == 0);
+ BOOST_TEST(boost::get_deleter<deleter2>(p) == 0);
+ BOOST_TEST(boost::get_deleter<deleter2 const>(p) == 0);
+
+ deleter * q = boost::get_deleter<deleter>(p);
+
+ BOOST_TEST(q != 0);
+ BOOST_TEST(q->data == 0);
+
+ q->data = 17041;
+
+ deleter const * r = boost::get_deleter<deleter const>(p);
+
+ BOOST_TEST(r == q);
+ BOOST_TEST(r->data == 17041);
+ }
+
+ return boost::report_errors();
+}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk