15a83710eSEric Fiselier //===----------------------------------------------------------------------===// 25a83710eSEric Fiselier // 357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 65a83710eSEric Fiselier // 75a83710eSEric Fiselier //===----------------------------------------------------------------------===// 85a83710eSEric Fiselier 95a83710eSEric Fiselier // <functional> 105a83710eSEric Fiselier 115a83710eSEric Fiselier // template <class T> 125a83710eSEric Fiselier // struct hash 135a83710eSEric Fiselier // { 145a83710eSEric Fiselier // size_t operator()(T val) const; 155a83710eSEric Fiselier // }; 165a83710eSEric Fiselier 175a83710eSEric Fiselier // Not very portable 185a83710eSEric Fiselier 195a83710eSEric Fiselier #include <string> 205a83710eSEric Fiselier #include <cassert> 215a83710eSEric Fiselier #include <type_traits> 225a83710eSEric Fiselier 237c803385SMarshall Clow #include "test_macros.h" 247c803385SMarshall Clow 255a83710eSEric Fiselier template <class T> 265a83710eSEric Fiselier void test()275a83710eSEric Fiseliertest() 285a83710eSEric Fiselier { 295a83710eSEric Fiselier typedef std::hash<T> H; 30*681cde7dSNikolas Klauser #if TEST_STD_VER <= 14 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), "" ); 33*681cde7dSNikolas Klauser #endif 347c803385SMarshall Clow ASSERT_NOEXCEPT(H()(T())); 357c803385SMarshall Clow 365a83710eSEric Fiselier H h; 375a83710eSEric Fiselier std::string g1 = "1234567890"; 385a83710eSEric Fiselier std::string g2 = "1234567891"; 395a83710eSEric Fiselier T s1(g1.begin(), g1.end()); 405a83710eSEric Fiselier T s2(g2.begin(), g2.end()); 415a83710eSEric Fiselier assert(h(s1) != h(s2)); 425a83710eSEric Fiselier } 435a83710eSEric Fiselier main(int,char **)442df59c50SJF Bastienint main(int, char**) 455a83710eSEric Fiselier { 465a83710eSEric Fiselier test<std::string>(); 477dad0bd6SMarshall Clow #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L 487dad0bd6SMarshall Clow test<std::u8string>(); 497dad0bd6SMarshall Clow #endif 505a83710eSEric Fiselier test<std::u16string>(); 515a83710eSEric Fiselier test<std::u32string>(); 52f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS 535a83710eSEric Fiselier test<std::wstring>(); 54f4c1258dSLouis Dionne #endif 552df59c50SJF Bastien 562df59c50SJF Bastien return 0; 575a83710eSEric Fiselier } 58