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

source code of libcxx/test/std/strings/basic.string/string.nonmembers/string_op!=/string_view_string.pass.cpp