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
19template <class S, class SV>
20TEST_CONSTEXPR_CXX20 void test(const S& lhs, SV rhs, bool x) {
21 assert((lhs < rhs) == x);
22}
23
24template <class CharT, template <class> class Alloc>
25TEST_CONSTEXPR_CXX20 void test_string() {
26 using S = std::basic_string<CharT, std::char_traits<CharT>, Alloc<CharT> >;
27 using SV = std::basic_string_view<CharT, std::char_traits<CharT> >;
28 test(S(""), SV(""), false);
29 test(S(""), SV("abcde"), true);
30 test(S(""), SV("abcdefghij"), true);
31 test(S(""), SV("abcdefghijklmnopqrst"), true);
32 test(S("abcde"), SV(""), false);
33 test(S("abcde"), SV("abcde"), false);
34 test(S("abcde"), SV("abcdefghij"), true);
35 test(S("abcde"), SV("abcdefghijklmnopqrst"), true);
36 test(S("abcdefghij"), SV(""), false);
37 test(S("abcdefghij"), SV("abcde"), false);
38 test(S("abcdefghij"), SV("abcdefghij"), false);
39 test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), true);
40 test(S("abcdefghijklmnopqrst"), SV(""), false);
41 test(S("abcdefghijklmnopqrst"), SV("abcde"), false);
42 test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), false);
43 test(S("abcdefghijklmnopqrst"), SV("abcdefghijklmnopqrst"), false);
44}
45
46TEST_CONSTEXPR_CXX20 bool test() {
47 test_string<char, std::allocator>();
48#if TEST_STD_VER >= 11
49 test_string<char, min_allocator>();
50#endif
51
52 return true;
53}
54
55int main(int, char**) {
56 test();
57#if TEST_STD_VER > 17
58 static_assert(test());
59#endif
60
61 return 0;
62}
63

source code of libcxx/test/std/strings/basic.string/string.nonmembers/string_oplt/string_string_view.pass.cpp