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 //     : public unary_function<T, size_t>
145a83710eSEric Fiselier // {
155a83710eSEric Fiselier //     size_t operator()(T val) const;
165a83710eSEric Fiselier // };
175a83710eSEric Fiselier 
185a83710eSEric Fiselier // Not very portable
195a83710eSEric Fiselier 
205a83710eSEric Fiselier #include <string>
215a83710eSEric Fiselier #include <cassert>
225a83710eSEric Fiselier #include <type_traits>
235a83710eSEric Fiselier 
247c803385SMarshall Clow #include "test_macros.h"
257c803385SMarshall Clow 
265a83710eSEric Fiselier template <class T>
275a83710eSEric Fiselier void
285a83710eSEric Fiselier test()
295a83710eSEric Fiselier {
305a83710eSEric Fiselier     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), "" );
337c803385SMarshall Clow     ASSERT_NOEXCEPT(H()(T()));
347c803385SMarshall Clow 
355a83710eSEric Fiselier     H h;
365a83710eSEric Fiselier     std::string g1 = "1234567890";
375a83710eSEric Fiselier     std::string g2 = "1234567891";
385a83710eSEric Fiselier     T s1(g1.begin(), g1.end());
395a83710eSEric Fiselier     T s2(g2.begin(), g2.end());
405a83710eSEric Fiselier     assert(h(s1) != h(s2));
415a83710eSEric Fiselier }
425a83710eSEric Fiselier 
43*2df59c50SJF Bastien int main(int, char**)
445a83710eSEric Fiselier {
455a83710eSEric Fiselier     test<std::string>();
467dad0bd6SMarshall Clow #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
477dad0bd6SMarshall Clow     test<std::u8string>();
487dad0bd6SMarshall Clow #endif
495a83710eSEric Fiselier #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
505a83710eSEric Fiselier     test<std::u16string>();
515a83710eSEric Fiselier     test<std::u32string>();
525a83710eSEric Fiselier #endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
535a83710eSEric Fiselier     test<std::wstring>();
54*2df59c50SJF Bastien 
55*2df59c50SJF Bastien   return 0;
565a83710eSEric Fiselier }
57