15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
35a83710eSEric Fiselier //                     The LLVM Compiler Infrastructure
45a83710eSEric Fiselier //
55a83710eSEric Fiselier // This file is dual licensed under the MIT and the University of Illinois Open
65a83710eSEric Fiselier // Source Licenses. See LICENSE.TXT for details.
75a83710eSEric Fiselier //
85a83710eSEric Fiselier //===----------------------------------------------------------------------===//
95a83710eSEric Fiselier 
105a83710eSEric Fiselier // <functional>
115a83710eSEric Fiselier 
125a83710eSEric Fiselier // template <class T>
135a83710eSEric Fiselier // struct hash
145a83710eSEric Fiselier //     : public unary_function<T, size_t>
155a83710eSEric Fiselier // {
165a83710eSEric Fiselier //     size_t operator()(T val) const;
175a83710eSEric Fiselier // };
185a83710eSEric Fiselier 
195a83710eSEric Fiselier // Not very portable
205a83710eSEric Fiselier 
215a83710eSEric Fiselier #include <functional>
225a83710eSEric Fiselier #include <cassert>
235a83710eSEric Fiselier #include <type_traits>
245a83710eSEric Fiselier #include <limits>
255a83710eSEric Fiselier 
265a83710eSEric Fiselier template <class T>
275a83710eSEric Fiselier void
285a83710eSEric Fiselier test()
295a83710eSEric Fiselier {
30d95510ebSMarshall Clow     typedef std::hash<T> H;
31d95510ebSMarshall Clow     static_assert((std::is_same<typename H::argument_type, T>::value), "" );
32d95510ebSMarshall Clow     static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
33d95510ebSMarshall Clow     H h;
34d95510ebSMarshall Clow 
355a83710eSEric Fiselier     for (int i = 0; i <= 5; ++i)
365a83710eSEric Fiselier     {
375a83710eSEric Fiselier         T t(i);
385a83710eSEric Fiselier         if (sizeof(T) <= sizeof(std::size_t))
395a83710eSEric Fiselier             assert(h(t) == t);
405a83710eSEric Fiselier     }
415a83710eSEric Fiselier }
425a83710eSEric Fiselier 
435a83710eSEric Fiselier int main()
445a83710eSEric Fiselier {
455a83710eSEric Fiselier     test<bool>();
465a83710eSEric Fiselier     test<char>();
475a83710eSEric Fiselier     test<signed char>();
485a83710eSEric Fiselier     test<unsigned char>();
495a83710eSEric Fiselier     test<char16_t>();
505a83710eSEric Fiselier     test<char32_t>();
515a83710eSEric Fiselier     test<wchar_t>();
525a83710eSEric Fiselier     test<short>();
535a83710eSEric Fiselier     test<unsigned short>();
545a83710eSEric Fiselier     test<int>();
555a83710eSEric Fiselier     test<unsigned int>();
565a83710eSEric Fiselier     test<long>();
575a83710eSEric Fiselier     test<unsigned long>();
585a83710eSEric Fiselier     test<long long>();
595a83710eSEric Fiselier     test<unsigned long long>();
60*1867554cSMarshall Clow 
61*1867554cSMarshall Clow //	LWG #2119
62*1867554cSMarshall Clow     test<ptrdiff_t>();
63*1867554cSMarshall Clow     test<size_t>();
64*1867554cSMarshall Clow 
65*1867554cSMarshall Clow 	test<int8_t>();
66*1867554cSMarshall Clow 	test<int16_t>();
67*1867554cSMarshall Clow 	test<int32_t>();
68*1867554cSMarshall Clow 	test<int64_t>();
69*1867554cSMarshall Clow 
70*1867554cSMarshall Clow 	test<int_fast8_t>();
71*1867554cSMarshall Clow 	test<int_fast16_t>();
72*1867554cSMarshall Clow 	test<int_fast32_t>();
73*1867554cSMarshall Clow 	test<int_fast64_t>();
74*1867554cSMarshall Clow 
75*1867554cSMarshall Clow 	test<int_least8_t>();
76*1867554cSMarshall Clow 	test<int_least16_t>();
77*1867554cSMarshall Clow 	test<int_least32_t>();
78*1867554cSMarshall Clow 	test<int_least64_t>();
79*1867554cSMarshall Clow 
80*1867554cSMarshall Clow     test<intmax_t>();
81*1867554cSMarshall Clow     test<intptr_t>();
82*1867554cSMarshall Clow 
83*1867554cSMarshall Clow 	test<uint8_t>();
84*1867554cSMarshall Clow 	test<uint16_t>();
85*1867554cSMarshall Clow 	test<uint32_t>();
86*1867554cSMarshall Clow 	test<uint64_t>();
87*1867554cSMarshall Clow 
88*1867554cSMarshall Clow 	test<uint_fast8_t>();
89*1867554cSMarshall Clow 	test<uint_fast16_t>();
90*1867554cSMarshall Clow 	test<uint_fast32_t>();
91*1867554cSMarshall Clow 	test<uint_fast64_t>();
92*1867554cSMarshall Clow 
93*1867554cSMarshall Clow 	test<uint_least8_t>();
94*1867554cSMarshall Clow 	test<uint_least16_t>();
95*1867554cSMarshall Clow 	test<uint_least32_t>();
96*1867554cSMarshall Clow 	test<uint_least64_t>();
97*1867554cSMarshall Clow 
98*1867554cSMarshall Clow     test<uintmax_t>();
99*1867554cSMarshall Clow     test<uintptr_t>();
1005a83710eSEric Fiselier }
101