blob: e5f7ca616245bdfc015b00d5b785ec0bb8a06bba [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//
Howard Hinnant412dbeb2010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant3e519522010-05-11 19:42:16 +00007//
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);
Howard Hinnantf3d14a62011-12-05 00:08:45 +000036 if (sizeof(T) <= sizeof(std::size_t))
37 assert(h(t) == t);
Howard Hinnant3e519522010-05-11 19:42:16 +000038 }
39}
40
41int main()
42{
43 test<bool>();
44 test<char>();
45 test<signed char>();
46 test<unsigned char>();
47 test<char16_t>();
48 test<char32_t>();
49 test<wchar_t>();
50 test<short>();
51 test<unsigned short>();
52 test<int>();
53 test<unsigned int>();
54 test<long>();
55 test<unsigned long>();
56 test<long long>();
57 test<unsigned long long>();
58}