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 // <string>
10
11 // we get this comparison "for free" because the string implicitly converts to the string_view
12
13 #include <string>
14 #include <cassert>
15
16 #include "test_macros.h"
17 #include "min_allocator.h"
18
19 template <class S, class SV>
20 TEST_CONSTEXPR_CXX20 void
test(const S & lhs,SV rhs,bool x)21 test(const S& lhs, SV rhs, bool x)
22 {
23 assert((lhs > rhs) == x);
24 }
25
test()26 TEST_CONSTEXPR_CXX20 bool test() {
27 {
28 typedef std::string S;
29 typedef std::string_view SV;
30 test(S(""), SV(""), false);
31 test(S(""), SV("abcde"), false);
32 test(S(""), SV("abcdefghij"), false);
33 test(S(""), SV("abcdefghijklmnopqrst"), false);
34 test(S("abcde"), SV(""), true);
35 test(S("abcde"), SV("abcde"), false);
36 test(S("abcde"), SV("abcdefghij"), false);
37 test(S("abcde"), SV("abcdefghijklmnopqrst"), false);
38 test(S("abcdefghij"), SV(""), true);
39 test(S("abcdefghij"), SV("abcde"), true);
40 test(S("abcdefghij"), SV("abcdefghij"), false);
41 test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), false);
42 test(S("abcdefghijklmnopqrst"), SV(""), true);
43 test(S("abcdefghijklmnopqrst"), SV("abcde"), true);
44 test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), true);
45 test(S("abcdefghijklmnopqrst"), SV("abcdefghijklmnopqrst"), false);
46 }
47 #if TEST_STD_VER >= 11
48 {
49 typedef std::basic_string <char, std::char_traits<char>, min_allocator<char>> S;
50 typedef std::basic_string_view<char, std::char_traits<char>> SV;
51 test(S(""), SV(""), false);
52 test(S(""), SV("abcde"), false);
53 test(S(""), SV("abcdefghij"), false);
54 test(S(""), SV("abcdefghijklmnopqrst"), false);
55 test(S("abcde"), SV(""), true);
56 test(S("abcde"), SV("abcde"), false);
57 test(S("abcde"), SV("abcdefghij"), false);
58 test(S("abcde"), SV("abcdefghijklmnopqrst"), false);
59 test(S("abcdefghij"), SV(""), true);
60 test(S("abcdefghij"), SV("abcde"), true);
61 test(S("abcdefghij"), SV("abcdefghij"), false);
62 test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), false);
63 test(S("abcdefghijklmnopqrst"), SV(""), true);
64 test(S("abcdefghijklmnopqrst"), SV("abcde"), true);
65 test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), true);
66 test(S("abcdefghijklmnopqrst"), SV("abcdefghijklmnopqrst"), false);
67 }
68 #endif
69
70 return true;
71 }
72
main(int,char **)73 int main(int, char**)
74 {
75 test();
76 #if TEST_STD_VER > 17
77 static_assert(test());
78 #endif
79
80 return 0;
81 }
82