1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <functional>
11 
12 // template <class T>
13 // struct hash
14 //     : public unary_function<T, size_t>
15 // {
16 //     size_t operator()(T val) const;
17 // };
18 
19 // Not very portable
20 
21 #include <functional>
22 #include <cassert>
23 #include <type_traits>
24 #include <limits>
25 
26 #include "test_macros.h"
27 
28 template <class T>
29 void
30 test()
31 {
32     typedef std::hash<T> H;
33     static_assert((std::is_same<typename H::argument_type, T>::value), "" );
34     static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
35     ASSERT_NOEXCEPT(H()(T()));
36     H h;
37 
38     typedef typename std::remove_pointer<T>::type type;
39     type i;
40     type j;
41     assert(h(&i) != h(&j));
42 }
43 
44 void test_nullptr()
45 {
46     typedef std::nullptr_t T;
47     typedef std::hash<T> H;
48     static_assert((std::is_same<typename H::argument_type, T>::value), "" );
49     static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
50     ASSERT_NOEXCEPT(H()(T()));
51 }
52 
53 int main()
54 {
55     test<int*>();
56     test_nullptr();
57 }
58