blob: 6e5c9add5286539aee2b44749cd7a008c1b2baaf [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnant5b08a8a2010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:16 +00004//
5// This file is distributed under the University of Illinois Open Source
6// License. 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
26template <class T>
27void
28test()
29{
30 static_assert((std::is_base_of<std::unary_function<T, std::size_t>,
31 std::hash<T> >::value), "");
32 std::hash<T> h;
33 for (int i = 0; i <= 5; ++i)
34 {
35 T t(i);
36 assert(h(t) == t);
37 }
38}
39
40int main()
41{
42 test<bool>();
43 test<char>();
44 test<signed char>();
45 test<unsigned char>();
46 test<char16_t>();
47 test<char32_t>();
48 test<wchar_t>();
49 test<short>();
50 test<unsigned short>();
51 test<int>();
52 test<unsigned int>();
53 test<long>();
54 test<unsigned long>();
55 test<long long>();
56 test<unsigned long long>();
57}