//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // Starting with C++20 the spaceship operator was included. This tests // comparison in that context, thus doesn't support older language versions. // These are tested per operator. // UNSUPPORTED: c++03, c++11, c++14, c++17 // // template // see below operator<=>(const basic_string& lhs, // const basic_string& rhs) noexcept; // template // see below operator<=>(const basic_string& lhs, // const charT* rhs); #include #include #include #include #include "constexpr_char_traits.h" #include "make_string.h" #include "test_comparisons.h" #include "test_macros.h" #define STR(S) MAKE_STRING(CharT, S) template constexpr void test() { AssertOrderAreNoexcept(); AssertOrderReturn(); using CharT = typename T::value_type; AssertOrderReturn(); // sorted values std::array v{ STR(""), STR("abc"), STR("abcdef"), STR("acb"), }; // sorted values with embedded NUL character std::array vn{ STR("abc"), STR("abc\0"), STR("abc\0def"), STR("acb\0"), }; static_assert(v.size() == vn.size()); for (std::size_t i = 0; i < v.size(); ++i) { for (std::size_t j = 0; j < v.size(); ++j) { assert(testOrder(v[i], v[j], i == j ? Ordering::equivalent : i < j ? Ordering::less : Ordering::greater)); assert(testOrder( v[i], std::basic_string{v[j]}.c_str(), i == j ? Ordering::equivalent : i < j ? Ordering::less : Ordering::greater)); // NUL test omitted for c-strings since it will fail. assert(testOrder(vn[i], vn[j], i == j ? Ordering::equivalent : i < j ? Ordering::less : Ordering::greater)); } } } constexpr bool test_all_types() { test(); test>, std::weak_ordering>(); #ifndef TEST_HAS_NO_WIDE_CHARACTERS test(); test>, std::weak_ordering>(); #endif test(); test>, std::weak_ordering>(); test(); test>, std::weak_ordering>(); test(); test>, std::weak_ordering>(); return true; } int main(int, char**) { test_all_types(); static_assert(test_all_types()); return 0; }