diff --git a/include/boost/array.hpp b/include/boost/array.hpp index 61d50e7..fa06fa9 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -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 or Trac issue #3168 @@ -46,6 +47,7 @@ // Handles broken standard libraries better than #include #include +#include #include // FIXES for broken compilers @@ -427,6 +429,13 @@ namespace boost { } #endif + + template + std::size_t hash_value(const array& arr) + { + return boost::hash_range(arr.begin(), arr.end()); + } + } /* namespace boost */ diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 2deb3d5..a09ba68 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -12,4 +12,5 @@ test-suite array : [ run array4.cpp ] [ run array5.cpp ] [ run array6.cpp ] + [ run array_hash.cpp ] ; diff --git a/test/array_hash.cpp b/test/array_hash.cpp new file mode 100644 index 0000000..474e29c --- /dev/null +++ b/test/array_hash.cpp @@ -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 +#include +#include +#include +#include + +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 ()); +// std::size_t hash1 = boost::hash > () ( boost::array ()); + + 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 () ( test_barr ); + std::size_t ahash = boost::hash () ( test_arr ); + if ( ahash != bhash ) + fail_test ( "Array_hash: Hash-mismatch on " ); +} + +} + +int main() +{ + RunTests< int >(); + RunTests< long >(); + RunTests< long double >(); + + return failed_tests; +} +