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"), true);
32     test(S(""), SV("abcdefghij"), true);
33     test(S(""), SV("abcdefghijklmnopqrst"), true);
34     test(S("abcde"), SV(""), false);
35     test(S("abcde"), SV("abcde"), false);
36     test(S("abcde"), SV("abcdefghij"), true);
37     test(S("abcde"), SV("abcdefghijklmnopqrst"), true);
38     test(S("abcdefghij"), SV(""), false);
39     test(S("abcdefghij"), SV("abcde"), false);
40     test(S("abcdefghij"), SV("abcdefghij"), false);
41     test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), true);
42     test(S("abcdefghijklmnopqrst"), SV(""), false);
43     test(S("abcdefghijklmnopqrst"), SV("abcde"), false);
44     test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), false);
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"), true);
53     test(S(""), SV("abcdefghij"), true);
54     test(S(""), SV("abcdefghijklmnopqrst"), true);
55     test(S("abcde"), SV(""), false);
56     test(S("abcde"), SV("abcde"), false);
57     test(S("abcde"), SV("abcdefghij"), true);
58     test(S("abcde"), SV("abcdefghijklmnopqrst"), true);
59     test(S("abcdefghij"), SV(""), false);
60     test(S("abcdefghij"), SV("abcde"), false);
61     test(S("abcdefghij"), SV("abcdefghij"), false);
62     test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), true);
63     test(S("abcdefghijklmnopqrst"), SV(""), false);
64     test(S("abcdefghijklmnopqrst"), SV("abcde"), false);
65     test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), false);
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