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