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