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>
24df5ddf2cSMarshall Clow #include <cstddef>
255a83710eSEric Fiselier #include <limits>
265a83710eSEric Fiselier 
275a83710eSEric Fiselier template <class T>
285a83710eSEric Fiselier void
295a83710eSEric Fiselier test()
305a83710eSEric Fiselier {
31d95510ebSMarshall Clow     typedef std::hash<T> H;
32d95510ebSMarshall Clow     static_assert((std::is_same<typename H::argument_type, T>::value), "" );
33d95510ebSMarshall Clow     static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
34d95510ebSMarshall Clow     H h;
35d95510ebSMarshall Clow 
365a83710eSEric Fiselier     for (int i = 0; i <= 5; ++i)
375a83710eSEric Fiselier     {
385a83710eSEric Fiselier         T t(i);
395a83710eSEric Fiselier         if (sizeof(T) <= sizeof(std::size_t))
405a83710eSEric Fiselier             assert(h(t) == t);
415a83710eSEric Fiselier     }
425a83710eSEric Fiselier }
435a83710eSEric Fiselier 
445a83710eSEric Fiselier int main()
455a83710eSEric Fiselier {
465a83710eSEric Fiselier     test<bool>();
475a83710eSEric Fiselier     test<char>();
485a83710eSEric Fiselier     test<signed char>();
495a83710eSEric Fiselier     test<unsigned char>();
505a83710eSEric Fiselier     test<char16_t>();
515a83710eSEric Fiselier     test<char32_t>();
525a83710eSEric Fiselier     test<wchar_t>();
535a83710eSEric Fiselier     test<short>();
545a83710eSEric Fiselier     test<unsigned short>();
555a83710eSEric Fiselier     test<int>();
565a83710eSEric Fiselier     test<unsigned int>();
575a83710eSEric Fiselier     test<long>();
585a83710eSEric Fiselier     test<unsigned long>();
595a83710eSEric Fiselier     test<long long>();
605a83710eSEric Fiselier     test<unsigned long long>();
611867554cSMarshall Clow 
621867554cSMarshall Clow //	LWG #2119
63df5ddf2cSMarshall Clow     test<std::ptrdiff_t>();
641867554cSMarshall Clow     test<size_t>();
651867554cSMarshall Clow 
661867554cSMarshall Clow 	test<int8_t>();
671867554cSMarshall Clow 	test<int16_t>();
681867554cSMarshall Clow 	test<int32_t>();
691867554cSMarshall Clow 	test<int64_t>();
701867554cSMarshall Clow 
711867554cSMarshall Clow 	test<int_fast8_t>();
721867554cSMarshall Clow 	test<int_fast16_t>();
731867554cSMarshall Clow 	test<int_fast32_t>();
741867554cSMarshall Clow 	test<int_fast64_t>();
751867554cSMarshall Clow 
761867554cSMarshall Clow 	test<int_least8_t>();
771867554cSMarshall Clow 	test<int_least16_t>();
781867554cSMarshall Clow 	test<int_least32_t>();
791867554cSMarshall Clow 	test<int_least64_t>();
801867554cSMarshall Clow 
811867554cSMarshall Clow     test<intmax_t>();
821867554cSMarshall Clow     test<intptr_t>();
831867554cSMarshall Clow 
841867554cSMarshall Clow 	test<uint8_t>();
851867554cSMarshall Clow 	test<uint16_t>();
861867554cSMarshall Clow 	test<uint32_t>();
871867554cSMarshall Clow 	test<uint64_t>();
881867554cSMarshall Clow 
891867554cSMarshall Clow 	test<uint_fast8_t>();
901867554cSMarshall Clow 	test<uint_fast16_t>();
911867554cSMarshall Clow 	test<uint_fast32_t>();
921867554cSMarshall Clow 	test<uint_fast64_t>();
931867554cSMarshall Clow 
941867554cSMarshall Clow 	test<uint_least8_t>();
951867554cSMarshall Clow 	test<uint_least16_t>();
961867554cSMarshall Clow 	test<uint_least32_t>();
971867554cSMarshall Clow 	test<uint_least64_t>();
981867554cSMarshall Clow 
991867554cSMarshall Clow     test<uintmax_t>();
1001867554cSMarshall Clow     test<uintptr_t>();
101*df691e18SEric Fiselier 
102*df691e18SEric Fiselier #ifndef _LIBCPP_HAS_NO_INT128
103*df691e18SEric Fiselier     test<__int128_t>();
104*df691e18SEric Fiselier     test<__uint128_t>();
105*df691e18SEric Fiselier #endif
1065a83710eSEric Fiselier }
107