[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / strings / basic.string.hash / strings.pass.cpp
blobc2a2ef95647243a678da395f95275a1eb916aa8a
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 //===----------------------------------------------------------------------===//
9 // <functional>
11 // template <class T>
12 // struct hash
13 // : public unary_function<T, size_t>
14 // {
15 // size_t operator()(T val) const;
16 // };
18 // Not very portable
20 #include <string>
21 #include <cassert>
22 #include <type_traits>
24 #include "test_macros.h"
26 template <class T>
27 void
28 test()
30 typedef std::hash<T> H;
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 ASSERT_NOEXCEPT(H()(T()));
35 H h;
36 std::string g1 = "1234567890";
37 std::string g2 = "1234567891";
38 T s1(g1.begin(), g1.end());
39 T s2(g2.begin(), g2.end());
40 assert(h(s1) != h(s2));
43 int main(int, char**)
45 test<std::string>();
46 #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
47 test<std::u8string>();
48 #endif
49 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
50 test<std::u16string>();
51 test<std::u32string>();
52 #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
53 test<std::wstring>();
55 return 0;