1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // <functional> 10 11 // template <class T> 12 // struct hash 13 // { 14 // size_t operator()(T val) const; 15 // }; 16 17 // Not very portable 18 19 #include <string> 20 #include <cassert> 21 #include <type_traits> 22 23 #include "test_macros.h" 24 25 template <class T> 26 void 27 test() 28 { 29 typedef std::hash<T> H; 30 #if TEST_STD_VER <= 14 31 static_assert((std::is_same<typename H::argument_type, T>::value), "" ); 32 static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" ); 33 #endif 34 ASSERT_NOEXCEPT(H()(T())); 35 36 H h; 37 std::string g1 = "1234567890"; 38 std::string g2 = "1234567891"; 39 T s1(g1.begin(), g1.end()); 40 T s2(g2.begin(), g2.end()); 41 assert(h(s1) != h(s2)); 42 } 43 44 int main(int, char**) 45 { 46 test<std::string>(); 47 #ifndef TEST_HAS_NO_CHAR8_T 48 test<std::u8string>(); 49 #endif 50 test<std::u16string>(); 51 test<std::u32string>(); 52 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 53 test<std::wstring>(); 54 #endif 55 56 return 0; 57 } 58