Debian Codegraph @

libcxx/test/std/strings/basic.string.hash/enabled_hashes.pass.cpp

raw
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 //===----------------------------------------------------------------------===//
8
9 // UNSUPPORTED: c++03
10
11 // <string>
12
13 // Test that <string> provides all of the arithmetic, enum, and pointer
14 // hash specializations.
15
16 #include <string>
17
18 #include "constexpr_char_traits.h"
19 #include "poisoned_hash_helper.h"
20 #include "test_allocator.h"
21 #include "test_macros.h"
22
23 struct MyChar {
24 char c;
25 };
26
27 template <>
28 struct std::char_traits<MyChar> {
29 using char_type = MyChar;
30 using int_type = std::char_traits<char>::int_type;
31 using off_type = std::char_traits<char>::off_type;
32 using pos_type = std::char_traits<char>::pos_type;
33 using state_type = std::char_traits<char>::state_type;
34
35 static void assign(char_type&, const char_type&);
36 static bool eq(char_type, char_type);
37 static bool lt(char_type, char_type);
38
39 static int compare(const char_type*, const char_type*, std::size_t);
40 static std::size_t length(const char_type*);
41 static const char_type* find(const char_type*, std::size_t, const char_type&);
42 static char_type* move(char_type*, const char_type*, std::size_t);
43 static char_type* copy(char_type*, const char_type*, std::size_t);
44 static char_type* assign(char_type*, std::size_t, char_type);
45
46 static int_type not_eof(int_type);
47 static char_type to_char_type(int_type);
48 static int_type to_int_type(char_type);
49 static bool eq_int_type(int_type, int_type);
50 static int_type eof();
51 };
52
53 int main(int, char**) {
54 test_library_hash_specializations_available();
55 {
56 test_hash_enabled_for_type<std::string>();
57 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
58 test_hash_enabled_for_type<std::wstring>();
59 #endif
60 #ifndef TEST_HAS_NO_CHAR8_T
61 test_hash_enabled_for_type<std::u8string>();
62 #endif
63 test_hash_enabled_for_type<std::u16string>();
64 test_hash_enabled_for_type<std::u32string>();
65 test_hash_enabled_for_type<std::basic_string<char, std::char_traits<char>, test_allocator<char>>>();
66 test_hash_disabled_for_type<std::basic_string<MyChar, std::char_traits<MyChar>, std::allocator<MyChar>>>();
67 test_hash_disabled_for_type<std::basic_string<char, constexpr_char_traits<char>, std::allocator<char>>>();
68 }
69
70 return 0;
71 }