hash_type_index_test.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2011 Daniel James.
  2. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #include "./config.hpp"
  5. #ifdef BOOST_HASH_TEST_STD_INCLUDES
  6. # include <functional>
  7. #else
  8. # include <boost/container_hash/hash.hpp>
  9. #endif
  10. #include <boost/config.hpp>
  11. #include <boost/core/lightweight_test.hpp>
  12. #if !defined(BOOST_NO_CXX11_HDR_TYPEINDEX)
  13. #include <typeindex>
  14. void test_type_index() {
  15. BOOST_HASH_TEST_NAMESPACE::hash<std::type_index> hasher;
  16. #if defined(BOOST_NO_TYPEID)
  17. std::cout<<"Unable to test std::type_index, as typeid isn't available"
  18. <<std::endl;
  19. #else
  20. std::type_index int_index = typeid(int);
  21. std::type_index int2_index = typeid(int);
  22. std::type_index char_index = typeid(char);
  23. BOOST_TEST(hasher(int_index) == int_index.hash_code());
  24. BOOST_TEST(hasher(int_index) == int2_index.hash_code());
  25. BOOST_TEST(hasher(char_index) == char_index.hash_code());
  26. BOOST_TEST(BOOST_HASH_TEST_NAMESPACE::hash_value(int_index) == int_index.hash_code());
  27. BOOST_TEST(BOOST_HASH_TEST_NAMESPACE::hash_value(int_index) == int2_index.hash_code());
  28. BOOST_TEST(BOOST_HASH_TEST_NAMESPACE::hash_value(char_index) == char_index.hash_code());
  29. BOOST_TEST(hasher(int_index) == hasher(int2_index));
  30. BOOST_TEST(hasher(int_index) != hasher(char_index));
  31. #endif
  32. }
  33. #endif
  34. int main()
  35. {
  36. #if !defined(BOOST_NO_CXX11_HDR_TYPEINDEX)
  37. test_type_index();
  38. #else
  39. std::cout<<"<type_index> not available."<<std::endl;
  40. #endif
  41. return boost::report_errors();
  42. }