1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
16 // size_t operator()(T val) const;
21 #include <string_view>
24 #include <type_traits>
26 #include "test_macros.h"
28 using std::string_view
;
32 typedef std::hash
<SV
> H
;
33 #if TEST_STD_VER <= 14
34 static_assert((std::is_same
<typename
H::argument_type
, SV
>::value
), "");
35 static_assert((std::is_same
<typename
H::result_type
, std::size_t>::value
), "");
38 typedef typename
SV::value_type char_type
;
39 typedef std::basic_string
<char_type
> String
;
40 typedef std::hash
<String
> SH
;
41 ASSERT_NOEXCEPT(H()(SV()));
45 for (int i
= 0; i
< 10; ++i
)
46 g1
[i
] = g2
[9 - i
] = static_cast<char_type
>('0' + i
);
53 assert(h(s1
) == h(s1
));
54 assert(h(s1
) != h(s2
));
55 assert(sh(ss1
) == h(s1
));
56 assert(sh(ss2
) == h(s2
));
59 int main(int, char**) {
60 test
<std::string_view
>();
61 #ifndef TEST_HAS_NO_CHAR8_T
62 test
<std::u8string_view
>();
64 test
<std::u16string_view
>();
65 test
<std::u32string_view
>();
66 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
67 test
<std::wstring_view
>();