Index: libcxx/include/string =================================================================== --- libcxx/include/string +++ libcxx/include/string @@ -356,63 +356,17 @@ template bool operator==(const basic_string& lhs, - const basic_string& rhs) noexcept; - -template -bool operator==(const charT* lhs, const basic_string& rhs) noexcept; + const basic_string& rhs) noexcept; template bool operator==(const basic_string& lhs, const charT* rhs) noexcept; template -bool operator!=(const basic_string& lhs, - const basic_string& rhs) noexcept; - -template -bool operator!=(const charT* lhs, const basic_string& rhs) noexcept; - -template -bool operator!=(const basic_string& lhs, const charT* rhs) noexcept; - -template -bool operator< (const basic_string& lhs, - const basic_string& rhs) noexcept; - -template -bool operator< (const basic_string& lhs, const charT* rhs) noexcept; - -template -bool operator< (const charT* lhs, const basic_string& rhs) noexcept; - -template -bool operator> (const basic_string& lhs, - const basic_string& rhs) noexcept; - -template -bool operator> (const basic_string& lhs, const charT* rhs) noexcept; - -template -bool operator> (const charT* lhs, const basic_string& rhs) noexcept; - -template -bool operator<=(const basic_string& lhs, - const basic_string& rhs) noexcept; - -template -bool operator<=(const basic_string& lhs, const charT* rhs) noexcept; - -template -bool operator<=(const charT* lhs, const basic_string& rhs) noexcept; - -template -bool operator>=(const basic_string& lhs, - const basic_string& rhs) noexcept; - -template -bool operator>=(const basic_string& lhs, const charT* rhs) noexcept; +bool operator<=>(const basic_string& lhs, + const basic_string& rhs) noexcept; template -bool operator>=(const charT* lhs, const basic_string& rhs) noexcept; +operator<=>(const basic_string& lhs, const charT* rhs) noexcept; template void swap(basic_string& lhs, @@ -3934,6 +3888,7 @@ } } +#ifdef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR // operator== template @@ -4135,6 +4090,43 @@ { return !(__lhs < __rhs); } +#else +template +_LIBCPP_INLINE_VISIBILITY +bool +operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs, + const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT +{ + return basic_string_view<_CharT, _Traits>(__lhs) == basic_string_view<_CharT, _Traits>(__rhs); +} + +template +_LIBCPP_INLINE_VISIBILITY +bool +operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs, + const _CharT* __rhs) _NOEXCEPT +{ + return basic_string_view<_CharT, _Traits>(__lhs) == basic_string_view<_CharT, _Traits>(__rhs); +} + +template +_LIBCPP_INLINE_VISIBILITY +auto +operator<=>(const basic_string<_CharT, _Traits, _Allocator>& __lhs, + const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT +{ + return basic_string_view<_CharT, _Traits>(__lhs) <=> basic_string_view<_CharT, _Traits>(__rhs); +} + +template +_LIBCPP_INLINE_VISIBILITY +auto +operator<=>(const basic_string<_CharT, _Traits, _Allocator>& __lhs, + const _CharT* __rhs) _NOEXCEPT +{ + return basic_string_view<_CharT, _Traits>(__lhs) <=> basic_string_view<_CharT, _Traits>(__rhs); +} +#endif // _LIBCPP_HAS_NO_SPACESHIP_OPERATOR // operator + Index: libcxx/test/std/strings/basic.string/string.nonmembers/string_opcmp/pointer_string.pass.cpp =================================================================== --- /dev/null +++ libcxx/test/std/strings/basic.string/string.nonmembers/string_opcmp/pointer_string.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 + +// + +// template +// bool operator<=>(const charT* lhs, const basic_string& rhs); + +#include +#include +#include + +#include "test_macros.h" +#include "min_allocator.h" + +template +void +test(const typename S::value_type* lhs, const S& rhs, std::weak_ordering x) +{ + assert((lhs <=> rhs) == x); +} + + +int main(int, char**) +{ + { + typedef std::string S; + test("", S(""), std::strong_ordering::equal); + test("", S("abcde"), std::strong_ordering::less); + test("", S("abcdefghij"), std::strong_ordering::less); + test("", S("abcdefghijklmnopqrst"), std::strong_ordering::less); + test("abcde", S(""), std::strong_ordering::greater); + test("abcde", S("abcde"), std::strong_ordering::equal); + test("abcde", S("abcdefghij"), std::strong_ordering::less); + test("abcde", S("abcdefghijklmnopqrst"), std::strong_ordering::less); + test("abcdefghij", S(""), std::strong_ordering::greater); + test("abcdefghij", S("abcde"), std::strong_ordering::greater); + test("abcdefghij", S("abcdefghij"), std::strong_ordering::equal); + test("abcdefghij", S("abcdefghijklmnopqrst"), std::strong_ordering::less); + test("abcdefghijklmnopqrst", S(""), std::strong_ordering::greater); + test("abcdefghijklmnopqrst", S("abcde"), std::strong_ordering::greater); + test("abcdefghijklmnopqrst", S("abcdefghij"), std::strong_ordering::greater); + test("abcdefghijklmnopqrst", S("abcdefghijklmnopqrst"), std::strong_ordering::equal); + } + + { + typedef std::basic_string, min_allocator> S; + test("", S(""), std::weak_ordering::equivalent); + test("", S("abcde"), std::weak_ordering::less); + test("", S("abcdefghij"), std::weak_ordering::less); + test("", S("abcdefghijklmnopqrst"), std::weak_ordering::less); + test("abcde", S(""), std::weak_ordering::greater); + test("abcde", S("abcde"), std::weak_ordering::equivalent); + test("abcde", S("abcdefghij"), std::weak_ordering::less); + test("abcde", S("abcdefghijklmnopqrst"), std::weak_ordering::less); + test("abcdefghij", S(""), std::weak_ordering::greater); + test("abcdefghij", S("abcde"), std::weak_ordering::greater); + test("abcdefghij", S("abcdefghij"), std::weak_ordering::equivalent); + test("abcdefghij", S("abcdefghijklmnopqrst"), std::weak_ordering::less); + test("abcdefghijklmnopqrst", S(""), std::weak_ordering::greater); + test("abcdefghijklmnopqrst", S("abcde"), std::weak_ordering::greater); + test("abcdefghijklmnopqrst", S("abcdefghij"), std::weak_ordering::greater); + test("abcdefghijklmnopqrst", S("abcdefghijklmnopqrst"), std::weak_ordering::equivalent); + } + + return 0; +} Index: libcxx/test/std/strings/basic.string/string.nonmembers/string_opcmp/string_pointer.pass.cpp =================================================================== --- /dev/null +++ libcxx/test/std/strings/basic.string/string.nonmembers/string_opcmp/string_pointer.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 + +// + +// template +// bool operator>(const basic_string& lhs, const charT* rhs); + +#include +#include +#include + +#include "test_macros.h" +#include "min_allocator.h" + +template +void +test(const S& lhs, const typename S::value_type* rhs, std::weak_ordering x) +{ + assert((lhs <=> rhs) == x); +} + +int main(int, char**) +{ + { + typedef std::string S; + test(S(""), "", std::strong_ordering::equal); + test(S(""), "abcde", std::strong_ordering::less); + test(S(""), "abcdefghij", std::strong_ordering::less); + test(S(""), "abcdefghijklmnopqrst", std::strong_ordering::less); + test(S("abcde"), "", std::strong_ordering::greater); + test(S("abcde"), "abcde", std::strong_ordering::equal); + test(S("abcde"), "abcdefghij", std::strong_ordering::less); + test(S("abcde"), "abcdefghijklmnopqrst", std::strong_ordering::less); + test(S("abcdefghij"), "", std::strong_ordering::greater); + test(S("abcdefghij"), "abcde", std::strong_ordering::greater); + test(S("abcdefghij"), "abcdefghij", std::strong_ordering::equal); + test(S("abcdefghij"), "abcdefghijklmnopqrst", std::strong_ordering::less); + test(S("abcdefghijklmnopqrst"), "", std::strong_ordering::greater); + test(S("abcdefghijklmnopqrst"), "abcde", std::strong_ordering::greater); + test(S("abcdefghijklmnopqrst"), "abcdefghij", std::strong_ordering::greater); + test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", std::strong_ordering::equal); + } + + { + typedef std::basic_string, min_allocator> S; + test(S(""), "", std::weak_ordering::equivalent); + test(S(""), "abcde", std::weak_ordering::less); + test(S(""), "abcdefghij", std::weak_ordering::less); + test(S(""), "abcdefghijklmnopqrst", std::weak_ordering::less); + test(S("abcde"), "", std::weak_ordering::greater); + test(S("abcde"), "abcde", std::weak_ordering::equivalent); + test(S("abcde"), "abcdefghij", std::weak_ordering::less); + test(S("abcde"), "abcdefghijklmnopqrst", std::weak_ordering::less); + test(S("abcdefghij"), "", std::weak_ordering::greater); + test(S("abcdefghij"), "abcde", std::weak_ordering::greater); + test(S("abcdefghij"), "abcdefghij", std::weak_ordering::equivalent); + test(S("abcdefghij"), "abcdefghijklmnopqrst", std::weak_ordering::less); + test(S("abcdefghijklmnopqrst"), "", std::weak_ordering::greater); + test(S("abcdefghijklmnopqrst"), "abcde", std::weak_ordering::greater); + test(S("abcdefghijklmnopqrst"), "abcdefghij", std::weak_ordering::greater); + test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", std::weak_ordering::equivalent); + } + + return 0; +} Index: libcxx/test/std/strings/basic.string/string.nonmembers/string_opcmp/string_string.pass.cpp =================================================================== --- /dev/null +++ libcxx/test/std/strings/basic.string/string.nonmembers/string_opcmp/string_string.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 + +// + +// we get this comparison "for free" because the string implicitly converts to the string_view + +#include +#include +#include + +#include "test_macros.h" +#include "min_allocator.h" + +template +void +test(const S& lhs, const S& rhs, std::weak_ordering x) +{ + assert((lhs <=> rhs) == x); +} + +int main(int, char**) +{ + { + typedef std::string S; + test(S(""), S(""), std::strong_ordering::equal); + test(S(""), S("abcde"), std::strong_ordering::less); + test(S(""), S("abcdefghij"), std::strong_ordering::less); + test(S(""), S("abcdefghijklmnopqrst"), std::strong_ordering::less); + test(S("abcde"), S(""), std::strong_ordering::greater); + test(S("abcde"), S("abcde"), std::strong_ordering::equal); + test(S("abcde"), S("abcdefghij"), std::strong_ordering::less); + test(S("abcde"), S("abcdefghijklmnopqrst"), std::strong_ordering::less); + test(S("abcdefghij"), S(""), std::strong_ordering::greater); + test(S("abcdefghij"), S("abcde"), std::strong_ordering::greater); + test(S("abcdefghij"), S("abcdefghij"), std::strong_ordering::equal); + test(S("abcdefghij"), S("abcdefghijklmnopqrst"), std::strong_ordering::less); + test(S("abcdefghijklmnopqrst"), S(""), std::strong_ordering::greater); + test(S("abcdefghijklmnopqrst"), S("abcde"), std::strong_ordering::greater); + test(S("abcdefghijklmnopqrst"), S("abcdefghij"), std::strong_ordering::greater); + test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), std::strong_ordering::equal); + } + + { + typedef std::basic_string , min_allocator> S; + test(S(""), S(""), std::weak_ordering::equivalent); + test(S(""), S("abcde"), std::weak_ordering::less); + test(S(""), S("abcdefghij"), std::weak_ordering::less); + test(S(""), S("abcdefghijklmnopqrst"), std::weak_ordering::less); + test(S("abcde"), S(""), std::weak_ordering::greater); + test(S("abcde"), S("abcde"), std::weak_ordering::equivalent); + test(S("abcde"), S("abcdefghij"), std::weak_ordering::less); + test(S("abcde"), S("abcdefghijklmnopqrst"), std::weak_ordering::less); + test(S("abcdefghij"), S(""), std::weak_ordering::greater); + test(S("abcdefghij"), S("abcde"), std::weak_ordering::greater); + test(S("abcdefghij"), S("abcdefghij"), std::weak_ordering::equivalent); + test(S("abcdefghij"), S("abcdefghijklmnopqrst"), std::weak_ordering::less); + test(S("abcdefghijklmnopqrst"), S(""), std::weak_ordering::greater); + test(S("abcdefghijklmnopqrst"), S("abcde"), std::weak_ordering::greater); + test(S("abcdefghijklmnopqrst"), S("abcdefghij"), std::weak_ordering::greater); + test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), std::weak_ordering::equivalent); + } + + return 0; +} Index: libcxx/test/std/strings/basic.string/string.nonmembers/string_opcmp/string_string_view.pass.cpp =================================================================== --- /dev/null +++ libcxx/test/std/strings/basic.string/string.nonmembers/string_opcmp/string_string_view.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 + +// + +// we get this comparison "for free" because the string implicitly converts to the string_view + +#include +#include +#include + +#include "test_macros.h" +#include "min_allocator.h" + +template +void +test(const S& lhs, SV rhs, std::weak_ordering x) +{ + assert((lhs <=> rhs) == x); +} + +int main(int, char**) +{ + { + typedef std::string S; + typedef std::string_view SV; + test(S(""), SV(""), std::strong_ordering::equal); + test(S(""), SV("abcde"), std::strong_ordering::less); + test(S(""), SV("abcdefghij"), std::strong_ordering::less); + test(S(""), SV("abcdefghijklmnopqrst"), std::strong_ordering::less); + test(S("abcde"), SV(""), std::strong_ordering::greater); + test(S("abcde"), SV("abcde"), std::strong_ordering::equal); + test(S("abcde"), SV("abcdefghij"), std::strong_ordering::less); + test(S("abcde"), SV("abcdefghijklmnopqrst"), std::strong_ordering::less); + test(S("abcdefghij"), SV(""), std::strong_ordering::greater); + test(S("abcdefghij"), SV("abcde"), std::strong_ordering::greater); + test(S("abcdefghij"), SV("abcdefghij"), std::strong_ordering::equal); + test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), std::strong_ordering::less); + test(S("abcdefghijklmnopqrst"), SV(""), std::strong_ordering::greater); + test(S("abcdefghijklmnopqrst"), SV("abcde"), std::strong_ordering::greater); + test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), std::strong_ordering::greater); + test(S("abcdefghijklmnopqrst"), SV("abcdefghijklmnopqrst"), std::strong_ordering::equal); + } + + { + typedef std::basic_string , min_allocator> S; + typedef std::basic_string_view> SV; + test(S(""), SV(""), std::weak_ordering::equivalent); + test(S(""), SV("abcde"), std::weak_ordering::less); + test(S(""), SV("abcdefghij"), std::weak_ordering::less); + test(S(""), SV("abcdefghijklmnopqrst"), std::weak_ordering::less); + test(S("abcde"), SV(""), std::weak_ordering::greater); + test(S("abcde"), SV("abcde"), std::weak_ordering::equivalent); + test(S("abcde"), SV("abcdefghij"), std::weak_ordering::less); + test(S("abcde"), SV("abcdefghijklmnopqrst"), std::weak_ordering::less); + test(S("abcdefghij"), SV(""), std::weak_ordering::greater); + test(S("abcdefghij"), SV("abcde"), std::weak_ordering::greater); + test(S("abcdefghij"), SV("abcdefghij"), std::weak_ordering::equivalent); + test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), std::weak_ordering::less); + test(S("abcdefghijklmnopqrst"), SV(""), std::weak_ordering::greater); + test(S("abcdefghijklmnopqrst"), SV("abcde"), std::weak_ordering::greater); + test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), std::weak_ordering::greater); + test(S("abcdefghijklmnopqrst"), SV("abcdefghijklmnopqrst"), std::weak_ordering::equivalent); + } + + return 0; +} Index: libcxx/test/std/strings/basic.string/string.nonmembers/string_opcmp/string_view_string.pass.cpp =================================================================== --- /dev/null +++ libcxx/test/std/strings/basic.string/string.nonmembers/string_opcmp/string_view_string.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 + +// + +// we get this comparison "for free" because the string implicitly converts to the string_view + +#include +#include +#include + +#include "test_macros.h" +#include "min_allocator.h" + +template +void +test(SV lhs, const S& rhs, std::weak_ordering x) +{ + assert((lhs <=> rhs) == x); +} + +int main(int, char**) +{ + { + typedef std::string S; + typedef std::string_view SV; + test(SV(""), S(""), std::strong_ordering::equal); + test(SV(""), S("abcde"), std::strong_ordering::less); + test(SV(""), S("abcdefghij"), std::strong_ordering::less); + test(SV(""), S("abcdefghijklmnopqrst"), std::strong_ordering::less); + test(SV("abcde"), S(""), std::strong_ordering::greater); + test(SV("abcde"), S("abcde"), std::strong_ordering::equal); + test(SV("abcde"), S("abcdefghij"), std::strong_ordering::less); + test(SV("abcde"), S("abcdefghijklmnopqrst"), std::strong_ordering::less); + test(SV("abcdefghij"), S(""), std::strong_ordering::greater); + test(SV("abcdefghij"), S("abcde"), std::strong_ordering::greater); + test(SV("abcdefghij"), S("abcdefghij"), std::strong_ordering::equal); + test(SV("abcdefghij"), S("abcdefghijklmnopqrst"), std::strong_ordering::less); + test(SV("abcdefghijklmnopqrst"), S(""), std::strong_ordering::greater); + test(SV("abcdefghijklmnopqrst"), S("abcde"), std::strong_ordering::greater); + test(SV("abcdefghijklmnopqrst"), S("abcdefghij"), std::strong_ordering::greater); + test(SV("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), std::strong_ordering::equal); + } + + { + typedef std::basic_string , min_allocator> S; + typedef std::basic_string_view> SV; + test(SV(""), S(""), std::weak_ordering::equivalent); + test(SV(""), S("abcde"), std::weak_ordering::less); + test(SV(""), S("abcdefghij"), std::weak_ordering::less); + test(SV(""), S("abcdefghijklmnopqrst"), std::weak_ordering::less); + test(SV("abcde"), S(""), std::weak_ordering::greater); + test(SV("abcde"), S("abcde"), std::weak_ordering::equivalent); + test(SV("abcde"), S("abcdefghij"), std::weak_ordering::less); + test(SV("abcde"), S("abcdefghijklmnopqrst"), std::weak_ordering::less); + test(SV("abcdefghij"), S(""), std::weak_ordering::greater); + test(SV("abcdefghij"), S("abcde"), std::weak_ordering::greater); + test(SV("abcdefghij"), S("abcdefghij"), std::weak_ordering::equivalent); + test(SV("abcdefghij"), S("abcdefghijklmnopqrst"), std::weak_ordering::less); + test(SV("abcdefghijklmnopqrst"), S(""), std::weak_ordering::greater); + test(SV("abcdefghijklmnopqrst"), S("abcde"), std::weak_ordering::greater); + test(SV("abcdefghijklmnopqrst"), S("abcdefghij"), std::weak_ordering::greater); + test(SV("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), std::weak_ordering::equivalent); + } + + return 0; +}