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 <string> 225a83710eSEric Fiselier #include <cassert> 235a83710eSEric Fiselier #include <type_traits> 245a83710eSEric Fiselier 257c803385SMarshall Clow #include "test_macros.h" 267c803385SMarshall Clow 275a83710eSEric Fiselier template <class T> 285a83710eSEric Fiselier void 295a83710eSEric Fiselier test() 305a83710eSEric Fiselier { 315a83710eSEric Fiselier 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), "" ); 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 445a83710eSEric Fiselier int main() 455a83710eSEric Fiselier { 465a83710eSEric Fiselier test<std::string>(); 47*7dad0bd6SMarshall Clow #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L 48*7dad0bd6SMarshall Clow test<std::u8string>(); 49*7dad0bd6SMarshall Clow #endif 505a83710eSEric Fiselier #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS 515a83710eSEric Fiselier test<std::u16string>(); 525a83710eSEric Fiselier test<std::u32string>(); 535a83710eSEric Fiselier #endif // _LIBCPP_HAS_NO_UNICODE_CHARS 545a83710eSEric Fiselier test<std::wstring>(); 555a83710eSEric Fiselier } 56