BPSectionOrderer: stabilize iteration order and node order
[llvm-project.git] / libcxx / test / std / strings / basic.string / string.ops / string_compare / pointer.pass.cpp
blobe1d23924517ffbf63e80fa25f1c5b3217d3e7dbf
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 //===----------------------------------------------------------------------===//
9 // <string>
11 // int compare(const charT *s) const; // constexpr since C++20
13 #include <string>
14 #include <cassert>
16 #include "test_macros.h"
17 #include "min_allocator.h"
19 TEST_CONSTEXPR_CXX20 int sign(int x) {
20 if (x == 0)
21 return 0;
22 if (x < 0)
23 return -1;
24 return 1;
27 template <class S>
28 TEST_CONSTEXPR_CXX20 void test(const S& s, const typename S::value_type* str, int x) {
29 LIBCPP_ASSERT_NOEXCEPT(s.compare(str));
30 assert(sign(s.compare(str)) == sign(x));
33 template <class S>
34 TEST_CONSTEXPR_CXX20 void test_string() {
35 test(S(""), "", 0);
36 test(S(""), "abcde", -5);
37 test(S(""), "abcdefghij", -10);
38 test(S(""), "abcdefghijklmnopqrst", -20);
39 test(S("abcde"), "", 5);
40 test(S("abcde"), "abcde", 0);
41 test(S("abcde"), "abcdefghij", -5);
42 test(S("abcde"), "abcdefghijklmnopqrst", -15);
43 test(S("abcdefghij"), "", 10);
44 test(S("abcdefghij"), "abcde", 5);
45 test(S("abcdefghij"), "abcdefghij", 0);
46 test(S("abcdefghij"), "abcdefghijklmnopqrst", -10);
47 test(S("abcdefghijklmnopqrst"), "", 20);
48 test(S("abcdefghijklmnopqrst"), "abcde", 15);
49 test(S("abcdefghijklmnopqrst"), "abcdefghij", 10);
50 test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", 0);
53 TEST_CONSTEXPR_CXX20 bool test() {
54 test_string<std::string>();
55 #if TEST_STD_VER >= 11
56 test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
57 #endif
59 return true;
62 int main(int, char**) {
63 test();
64 #if TEST_STD_VER > 17
65 static_assert(test());
66 #endif
68 return 0;