[libcxx] Use alias for detecting overriden function (#120805)
[llvm-project.git] / libcxx / test / std / strings / basic.string.hash / strings.pass.cpp
blob293336f3df93c14606166d2f7f217d708243caa5
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 // {
14 // size_t operator()(T val) const;
15 // };
17 // Not very portable
19 #include <string>
20 #include <cassert>
21 #include <type_traits>
23 #include "test_macros.h"
25 template <class T>
26 void test() {
27 typedef std::hash<T> H;
28 #if TEST_STD_VER <= 14
29 static_assert((std::is_same<typename H::argument_type, T>::value), "");
30 static_assert((std::is_same<typename H::result_type, std::size_t>::value), "");
31 #endif
32 ASSERT_NOEXCEPT(H()(T()));
34 H h;
35 std::string g1 = "1234567890";
36 std::string g2 = "1234567891";
37 T s1(g1.begin(), g1.end());
38 T s2(g2.begin(), g2.end());
39 assert(h(s1) != h(s2));
42 int main(int, char**) {
43 test<std::string>();
44 #ifndef TEST_HAS_NO_CHAR8_T
45 test<std::u8string>();
46 #endif
47 test<std::u16string>();
48 test<std::u32string>();
49 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
50 test<std::wstring>();
51 #endif
53 return 0;