Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r79516 - in trunk: boost/functional/hash boost/functional/hash/detail libs/functional/hash/test
From: dnljms_at_[hidden]
Date: 2012-07-14 18:32:30


Author: danieljames
Date: 2012-07-14 18:32:29 EDT (Sat, 14 Jul 2012)
New Revision: 79516
URL: http://svn.boost.org/trac/boost/changeset/79516

Log:
Hash: `std::shared_ptr`, `std::unique_ptr` support.
Added:
   trunk/libs/functional/hash/test/hash_std_smart_ptr_test.cpp (contents, props changed)
Text files modified:
   trunk/boost/functional/hash/detail/container_fwd_0x.hpp | 14 ++++++++++++++
   trunk/boost/functional/hash/extensions.hpp | 12 ++++++++++++
   trunk/libs/functional/hash/test/Jamfile.v2 | 1 +
   3 files changed, 27 insertions(+), 0 deletions(-)

Modified: trunk/boost/functional/hash/detail/container_fwd_0x.hpp
==============================================================================
--- trunk/boost/functional/hash/detail/container_fwd_0x.hpp (original)
+++ trunk/boost/functional/hash/detail/container_fwd_0x.hpp 2012-07-14 18:32:29 EDT (Sat, 14 Jul 2012)
@@ -38,4 +38,18 @@
 # endif
 #endif
 
+// std::shared_ptr/std::unique_ptr
+
+#if !defined(BOOST_NO_CXX11_HDR_MEMORY)
+# if (defined(BOOST_DETAIL_NO_CONTAINER_FWD) && \
+ !defined(BOOST_DETAIL_TEST_FORCE_CONTAINER_FWD))
+# include <memory>
+# else
+namespace std {
+ template <class> class shared_ptr;
+ template <class, class> class unique_ptr;
+}
+# endif
+#endif
+
 #endif

Modified: trunk/boost/functional/hash/extensions.hpp
==============================================================================
--- trunk/boost/functional/hash/extensions.hpp (original)
+++ trunk/boost/functional/hash/extensions.hpp 2012-07-14 18:32:29 EDT (Sat, 14 Jul 2012)
@@ -179,6 +179,18 @@
 
 #endif
 
+#if !defined(BOOST_NO_CXX11_HDR_MEMORY)
+ template <typename T>
+ inline std::size_t hash_value(std::shared_ptr<T> const& x) {
+ return boost::hash_value(x.get());
+ }
+
+ template <typename T, typename Deleter>
+ inline std::size_t hash_value(std::unique_ptr<T, Deleter> const& x) {
+ return boost::hash_value(x.get());
+ }
+#endif
+
     //
     // call_hash_impl
     //

Modified: trunk/libs/functional/hash/test/Jamfile.v2
==============================================================================
--- trunk/libs/functional/hash/test/Jamfile.v2 (original)
+++ trunk/libs/functional/hash/test/Jamfile.v2 2012-07-14 18:32:29 EDT (Sat, 14 Jul 2012)
@@ -42,6 +42,7 @@
         [ run hash_type_index_test.cpp ]
         [ run hash_std_array_test.cpp ]
         [ run hash_std_tuple_test.cpp ]
+ [ run hash_std_smart_ptr_test.cpp ]
         [ run link_test.cpp link_test_2.cpp ]
         [ run link_ext_test.cpp link_no_ext_test.cpp ]
         [ run extensions_hpp_test.cpp ]

Added: trunk/libs/functional/hash/test/hash_std_smart_ptr_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/functional/hash/test/hash_std_smart_ptr_test.cpp 2012-07-14 18:32:29 EDT (Sat, 14 Jul 2012)
@@ -0,0 +1,80 @@
+
+// Copyright 2012 Daniel James.
+// 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 "./config.hpp"
+
+#ifdef TEST_STD_INCLUDES
+# include <functional>
+#else
+# include <boost/functional/hash.hpp>
+#endif
+
+#include <boost/detail/lightweight_test.hpp>
+#include "./compile_time.hpp"
+
+#if defined(TEST_EXTENSIONS) && !defined(BOOST_NO_CXX11_HDR_TUPLE)
+#define TEST_SMART_PTRS
+#include <memory>
+#endif
+
+#ifdef TEST_SMART_PTRS
+
+void shared_ptr_tests()
+{
+ std::shared_ptr<int> x;
+ compile_time_tests(&x);
+
+ HASH_NAMESPACE::hash<std::shared_ptr<int> > x1;
+ HASH_NAMESPACE::hash<std::shared_ptr<int> > x2;
+
+ std::shared_ptr<int> ptr1(new int(10));
+ std::shared_ptr<int> ptr2;
+
+ BOOST_TEST(x1(x) == x2(ptr2));
+ BOOST_TEST(x1(x) != x2(ptr1));
+ ptr2.reset(new int(10));
+ BOOST_TEST(x1(ptr1) == x2(ptr1));
+ BOOST_TEST(x1(ptr1) != x2(ptr2));
+ ptr2 = ptr1;
+ BOOST_TEST(x1(ptr1) == x2(ptr2));
+#if defined(TEST_EXTENSIONS)
+ BOOST_TEST(x1(x) == HASH_NAMESPACE::hash_value(x));
+ BOOST_TEST(x1(ptr1) == HASH_NAMESPACE::hash_value(ptr2));
+#endif
+}
+
+void unique_ptr_tests()
+{
+ std::unique_ptr<int> x;
+ compile_time_tests(&x);
+
+ HASH_NAMESPACE::hash<std::unique_ptr<int> > x1;
+ HASH_NAMESPACE::hash<std::unique_ptr<int> > x2;
+
+ std::unique_ptr<int> ptr1(new int(10));
+ std::unique_ptr<int> ptr2;
+
+ BOOST_TEST(x1(x) == x2(ptr2));
+ BOOST_TEST(x1(x) != x2(ptr1));
+ ptr2.reset(new int(10));
+ BOOST_TEST(x1(ptr1) == x2(ptr1));
+ BOOST_TEST(x1(ptr1) != x2(ptr2));
+
+#if defined(TEST_EXTENSIONS)
+ BOOST_TEST(x1(x) == HASH_NAMESPACE::hash_value(x));
+#endif
+}
+
+#endif
+
+int main()
+{
+#ifdef TEST_SMART_PTRS
+ shared_ptr_tests();
+ unique_ptr_tests();
+#endif
+
+ 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