$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r77976 - in trunk: boost libs/array/test
From: marshall_at_[hidden]
Date: 2012-04-14 14:07:34
Author: marshall
Date: 2012-04-14 14:07:34 EDT (Sat, 14 Apr 2012)
New Revision: 77976
URL: http://svn.boost.org/trac/boost/changeset/77976
Log:
Added support for Boost.Hash to Boost.Array; fixes #6791
Added:
   trunk/libs/array/test/array_hash.cpp   (contents, props changed)
Text files modified: 
   trunk/boost/array.hpp            |     9 +++++++++                               
   trunk/libs/array/test/Jamfile.v2 |     1 +                                       
   2 files changed, 10 insertions(+), 0 deletions(-)
Modified: trunk/boost/array.hpp
==============================================================================
--- trunk/boost/array.hpp	(original)
+++ trunk/boost/array.hpp	2012-04-14 14:07:34 EDT (Sat, 14 Apr 2012)
@@ -13,6 +13,7 @@
  * accompanying file LICENSE_1_0.txt or copy at
  * http://www.boost.org/LICENSE_1_0.txt)
  *
+ * 14 Apr 2012 - (mtc) Added support for boost::hash
  * 28 Dec 2010 - (mtc) Added cbegin and cend (and crbegin and crend) for C++Ox compatibility.
  * 10 Mar 2010 - (mtc) fill method added, matching resolution of the standard library working group.
  *      See <http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#776> or Trac issue #3168
@@ -46,6 +47,7 @@
 // Handles broken standard libraries better than <iterator>
 #include <boost/detail/iterator.hpp>
 #include <boost/throw_exception.hpp>
+#include <boost/functional/hash_fwd.hpp>
 #include <algorithm>
 
 // FIXES for broken compilers
@@ -427,6 +429,13 @@
     }
 #endif
 
+
+    template<class T, std::size_t N>
+    std::size_t hash_value(const array<T,N>& arr)
+    {
+        return boost::hash_range(arr.begin(), arr.end());
+    }
+
 } /* namespace boost */
 
 
Modified: trunk/libs/array/test/Jamfile.v2
==============================================================================
--- trunk/libs/array/test/Jamfile.v2	(original)
+++ trunk/libs/array/test/Jamfile.v2	2012-04-14 14:07:34 EDT (Sat, 14 Apr 2012)
@@ -12,4 +12,5 @@
     [ run array4.cpp ]
     [ run array5.cpp ]
     [ run array6.cpp ]
+    [ run array_hash.cpp ]
     ;
Added: trunk/libs/array/test/array_hash.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/array/test/array_hash.cpp	2012-04-14 14:07:34 EDT (Sat, 14 Apr 2012)
@@ -0,0 +1,49 @@
+/* tests for using boost::hash with boost::array
+ * (C) Copyright Marshall Clow 2012
+ * 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 <string>
+#include <iostream>
+#include <boost/array.hpp>
+#include <algorithm>
+#include <boost/functional/hash.hpp>
+
+namespace {
+unsigned int failed_tests = 0;
+
+void    fail_test( const char * reason ) {
+    ++failed_tests;
+    std::cerr << "Test failure " << failed_tests << ": " << reason << std::endl;
+}
+
+template< class T >
+void    RunTests()
+{
+//    std::size_t hash0 = boost::hash<boost::array<T,0> > () ( boost::array<T, 0> ());
+//    std::size_t hash1 = boost::hash<boost::array<T,1> > () ( boost::array<T, 1> ());
+    
+    typedef boost::array< T, 5 >    barr;
+    typedef T arr[5];
+    barr           test_barr =   {{ 1, 1, 2, 3, 5 }};
+    arr            test_arr  =    { 1, 1, 2, 3, 5 };
+    
+    std::size_t bhash = boost::hash<barr> () ( test_barr );
+    std::size_t ahash = boost::hash<arr>  () ( test_arr );
+    if ( ahash != bhash )
+        fail_test ( "Array_hash: Hash-mismatch on " );
+}
+
+}
+
+int main()
+{
+    RunTests< int >();
+    RunTests< long >();
+    RunTests< long double >();
+
+    return failed_tests;
+}
+