summaryrefslogtreecommitdiff
path: root/libs/functional/hash/test/hash_type_index_test.cpp
blob: 7892918c42fa9c913e3070bb57877255ecda70ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

// Copyright 2011 Daniel James.
// 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 "./config.hpp"

#ifdef TEST_STD_INCLUDES
#  include <functional>
#else
#  include <boost/functional/hash.hpp>
#endif
#include <boost/config.hpp>
#include <boost/detail/lightweight_test.hpp>

#if !defined(BOOST_NO_0X_HDR_TYPEINDEX)

#include <typeindex>

void test_type_index() {
    std::type_index int_index = typeid(int);
    std::type_index int2_index = typeid(int);
    std::type_index char_index = typeid(char);
    
    HASH_NAMESPACE::hash<std::type_index> hasher;
    
    BOOST_TEST(hasher(int_index) == int_index.hash_code());
    BOOST_TEST(hasher(int_index) == int2_index.hash_code());
    BOOST_TEST(hasher(char_index) == char_index.hash_code());
    BOOST_TEST(HASH_NAMESPACE::hash_value(int_index) == int_index.hash_code());
    BOOST_TEST(HASH_NAMESPACE::hash_value(int_index) == int2_index.hash_code());
    BOOST_TEST(HASH_NAMESPACE::hash_value(char_index) == char_index.hash_code());

    BOOST_TEST(hasher(int_index) == hasher(int2_index));
    BOOST_TEST(hasher(int_index) != hasher(char_index));
}
#endif

int main()
{
#if !defined(BOOST_NO_0X_HDR_TYPEINDEX)
    test_type_index();
#else
    std::cout<<"<type_index> not available."<<std::endl;
#endif

    return boost::report_errors();
}