array_hash.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* tests for using boost::hash with boost::array
  2. * (C) Copyright Marshall Clow 2012
  3. * Distributed under the Boost Software License, Version 1.0. (See
  4. * accompanying file LICENSE_1_0.txt or copy at
  5. * http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. #include <string>
  8. #include <iostream>
  9. #include <boost/array.hpp>
  10. #include <algorithm>
  11. #include <boost/functional/hash.hpp>
  12. #include <boost/core/lightweight_test_trait.hpp>
  13. namespace {
  14. template< class T >
  15. void RunTests()
  16. {
  17. // std::size_t hash0 = boost::hash<boost::array<T,0> > () ( boost::array<T, 0> ());
  18. // std::size_t hash1 = boost::hash<boost::array<T,1> > () ( boost::array<T, 1> ());
  19. typedef boost::array< T, 5 > barr;
  20. typedef T arr[5];
  21. barr test_barr = {{ 1, 1, 2, 3, 5 }};
  22. arr test_arr = { 1, 1, 2, 3, 5 };
  23. std::size_t bhash = boost::hash<barr> () ( test_barr );
  24. std::size_t ahash = boost::hash<arr> () ( test_arr );
  25. BOOST_TEST ( ahash == bhash );
  26. }
  27. }
  28. int main()
  29. {
  30. RunTests< int >();
  31. RunTests< long >();
  32. RunTests< long double >();
  33. return boost::report_errors();
  34. }