From b69aa3f6f5dacac23aa13f05625e81023236c533 Mon Sep 17 00:00:00 2001 From: Anju Del Moral Gonzalez Date: Fri, 5 Feb 2021 13:43:43 -0800 Subject: [PATCH 01/11] added spaceship slice --- stl/inc/complex | 4 ++++ stl/inc/valarray | 5 +++++ tests/std/tests/P1614R2_spaceship/test.cpp | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/stl/inc/complex b/stl/inc/complex index e0aff1ed4ee..3ad89d08d3d 100644 --- a/stl/inc/complex +++ b/stl/inc/complex @@ -1514,12 +1514,15 @@ _NODISCARD constexpr bool operator==(const complex<_Ty>& _Left, const _Ty& _Righ return _Left.real() == _Right && _Left.imag() == 0; } +#if !_HAS_CXX20 template _NODISCARD constexpr bool operator==(const _Ty& _Left, const complex<_Ty>& _Right) { return _Left == _Right.real() && 0 == _Right.imag(); } +#endif //!_HAS_CXX20 // FUNCTION TEMPLATE operator!= +#if !_HAS_CXX20 template _NODISCARD constexpr bool operator!=(const complex<_Ty>& _Left, const complex<_Ty>& _Right) { return !(_Left == _Right); @@ -1534,6 +1537,7 @@ template _NODISCARD constexpr bool operator!=(const _Ty& _Left, const complex<_Ty>& _Right) { return !(_Left == _Right); } +#endif //!_HAS_CXX20 // FUNCTION TEMPLATE imag template diff --git a/stl/inc/valarray b/stl/inc/valarray index 63b69f34fa4..4f75086e6f8 100644 --- a/stl/inc/valarray +++ b/stl/inc/valarray @@ -1372,6 +1372,11 @@ public: _NODISCARD size_t stride() const noexcept /* strengthened */ { return _Stride; } +#if _HAS_CXX200 + friend bool operator==(const slice& x, const slice& y) { + return x.start() == y.start() && x.size() == y.size() && x.stride() == y.stride(); + } +#endif protected: size_t _Start = 0; // the starting offset diff --git a/tests/std/tests/P1614R2_spaceship/test.cpp b/tests/std/tests/P1614R2_spaceship/test.cpp index c488238b56f..d6ed0ad9f86 100644 --- a/tests/std/tests/P1614R2_spaceship/test.cpp +++ b/tests/std/tests/P1614R2_spaceship/test.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +28,7 @@ #include #include #include +#include #include template @@ -287,6 +289,23 @@ void ordering_test_cases() { std::forward_list b = {10, 20, 40}; ordered_containers_test(a, a, b); } + { // slice + std::valarray a(20); + for (int i = 0; i < 12; ++i) { + a[i] = i; + } + + const auto a1 = a[std::slice(2, 3, 4)]; + const auto a2 = a[std::slice(2, 3, 4)]; + const auto a3 = a[std::slice(3, 3, 4)]; + const auto a4 = a[std::slice(2, 4, 4)]; + const auto a5 = a[std::slice(2, 3, 3)]; + + static_assert((a1 == a2) == true); + static_assert((a1 == a3) == false); + static_assert((a1 == a4) == false); + static_assert((a1 == a5) == false); + } { // map std::map a1; a1["hi"] = 1; From 4466b063306640bc8fc088b76dea79b9bf51ec68 Mon Sep 17 00:00:00 2001 From: Anju Del Moral Gonzalez Date: Fri, 5 Feb 2021 16:23:27 -0800 Subject: [PATCH 02/11] going beyond the Standardese --- llvm-project | 2 +- stl/inc/complex | 4 +-- stl/inc/valarray | 9 +++--- tests/std/tests/P1614R2_spaceship/test.cpp | 35 +++++++++++----------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/llvm-project b/llvm-project index 60575179041..a668ad92d5e 160000 --- a/llvm-project +++ b/llvm-project @@ -1 +1 @@ -Subproject commit 605751790418ca4fb1df1e94dfbac34cfcc1b96f +Subproject commit a668ad92d5e2161e07e1a435a19ea5072f52a989 diff --git a/stl/inc/complex b/stl/inc/complex index 3ad89d08d3d..5e935cf52d0 100644 --- a/stl/inc/complex +++ b/stl/inc/complex @@ -1519,7 +1519,7 @@ template _NODISCARD constexpr bool operator==(const _Ty& _Left, const complex<_Ty>& _Right) { return _Left == _Right.real() && 0 == _Right.imag(); } -#endif //!_HAS_CXX20 +#endif // !_HAS_CXX20 // FUNCTION TEMPLATE operator!= #if !_HAS_CXX20 @@ -1537,7 +1537,7 @@ template _NODISCARD constexpr bool operator!=(const _Ty& _Left, const complex<_Ty>& _Right) { return !(_Left == _Right); } -#endif //!_HAS_CXX20 +#endif // !_HAS_CXX20 // FUNCTION TEMPLATE imag template diff --git a/stl/inc/valarray b/stl/inc/valarray index 4f75086e6f8..c636855d134 100644 --- a/stl/inc/valarray +++ b/stl/inc/valarray @@ -1372,11 +1372,12 @@ public: _NODISCARD size_t stride() const noexcept /* strengthened */ { return _Stride; } -#if _HAS_CXX200 - friend bool operator==(const slice& x, const slice& y) { - return x.start() == y.start() && x.size() == y.size() && x.stride() == y.stride(); + +#if _HAS_CXX20 + _NODISCARD friend bool operator==(const slice& _Left, const slice& _Right) const noexcept /* strengthened */ { + return _Left.start() == _Right.start() && _Left.size() == _Right.size() && _Left.stride() == _Right.stride(); } -#endif +#endif // !_HAS_CXX20 protected: size_t _Start = 0; // the starting offset diff --git a/tests/std/tests/P1614R2_spaceship/test.cpp b/tests/std/tests/P1614R2_spaceship/test.cpp index d6ed0ad9f86..8f58682f4c0 100644 --- a/tests/std/tests/P1614R2_spaceship/test.cpp +++ b/tests/std/tests/P1614R2_spaceship/test.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -289,23 +288,6 @@ void ordering_test_cases() { std::forward_list b = {10, 20, 40}; ordered_containers_test(a, a, b); } - { // slice - std::valarray a(20); - for (int i = 0; i < 12; ++i) { - a[i] = i; - } - - const auto a1 = a[std::slice(2, 3, 4)]; - const auto a2 = a[std::slice(2, 3, 4)]; - const auto a3 = a[std::slice(3, 3, 4)]; - const auto a4 = a[std::slice(2, 4, 4)]; - const auto a5 = a[std::slice(2, 3, 3)]; - - static_assert((a1 == a2) == true); - static_assert((a1 == a3) == false); - static_assert((a1 == a4) == false); - static_assert((a1 == a5) == false); - } { // map std::map a1; a1["hi"] = 1; @@ -502,6 +484,23 @@ void ordering_test_cases() { spaceship_test(c_mem[0], c_mem[0], c_mem[1]); } + { // slice + std::valarray a(20); + for (int i = 0; i < 20; ++i) { + a[i] = i; + } + + const auto a1 = a[std::slice(2, 3, 4)]; + const auto a2 = a[std::slice(2, 3, 4)]; + const auto a3 = a[std::slice(3, 3, 4)]; + const auto a4 = a[std::slice(2, 4, 4)]; + const auto a5 = a[std::slice(2, 3, 3)]; + + static_assert((a1 == a2) == true); + static_assert((a1 == a3) == false); + static_assert((a1 == a4) == false); + static_assert((a1 == a5) == false); + } { // filesystem::space_info constexpr std::filesystem::space_info si1{4'000'000'000'000, 2'000'000'000'000, 1'000'000'000'000}; constexpr std::filesystem::space_info si2{4'000'000'000'000, 2'000'000'000'000, 1'000'000'000'000}; From f454e5bfbbc7b52d3c9aceedd8c48dc3aaf0a9b7 Mon Sep 17 00:00:00 2001 From: Anju Del Moral Gonzalez Date: Mon, 8 Feb 2021 12:14:34 -0800 Subject: [PATCH 03/11] restore llvm --- llvm-project | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm-project b/llvm-project index a668ad92d5e..60575179041 160000 --- a/llvm-project +++ b/llvm-project @@ -1 +1 @@ -Subproject commit a668ad92d5e2161e07e1a435a19ea5072f52a989 +Subproject commit 605751790418ca4fb1df1e94dfbac34cfcc1b96f From df258e27d0b85017b4f2e0e52c0ad1307835e7b9 Mon Sep 17 00:00:00 2001 From: Anju Del Moral Gonzalez Date: Tue, 9 Feb 2021 17:33:51 -0800 Subject: [PATCH 04/11] removed valarray --- tests/std/tests/P1614R2_spaceship/test.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tests/std/tests/P1614R2_spaceship/test.cpp b/tests/std/tests/P1614R2_spaceship/test.cpp index 8f58682f4c0..f01c72e225b 100644 --- a/tests/std/tests/P1614R2_spaceship/test.cpp +++ b/tests/std/tests/P1614R2_spaceship/test.cpp @@ -485,16 +485,11 @@ void ordering_test_cases() { spaceship_test(c_mem[0], c_mem[0], c_mem[1]); } { // slice - std::valarray a(20); - for (int i = 0; i < 20; ++i) { - a[i] = i; - } - - const auto a1 = a[std::slice(2, 3, 4)]; - const auto a2 = a[std::slice(2, 3, 4)]; - const auto a3 = a[std::slice(3, 3, 4)]; - const auto a4 = a[std::slice(2, 4, 4)]; - const auto a5 = a[std::slice(2, 3, 3)]; + const auto a1 = std::slice(2, 3, 4); + const auto a2 = std::slice(2, 3, 4); + const auto a3 = std::slice(3, 3, 4); + const auto a4 = std::slice(2, 4, 4); + const auto a5 = std::slice(2, 3, 3); static_assert((a1 == a2) == true); static_assert((a1 == a3) == false); From e35b13eadf186312ad0f18040067e7ac13783b4c Mon Sep 17 00:00:00 2001 From: Anju Del Moral Gonzalez Date: Tue, 9 Feb 2021 18:18:13 -0800 Subject: [PATCH 05/11] compare directly --- tests/std/tests/P1614R2_spaceship/test.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/tests/std/tests/P1614R2_spaceship/test.cpp b/tests/std/tests/P1614R2_spaceship/test.cpp index f01c72e225b..77613c311ed 100644 --- a/tests/std/tests/P1614R2_spaceship/test.cpp +++ b/tests/std/tests/P1614R2_spaceship/test.cpp @@ -485,16 +485,10 @@ void ordering_test_cases() { spaceship_test(c_mem[0], c_mem[0], c_mem[1]); } { // slice - const auto a1 = std::slice(2, 3, 4); - const auto a2 = std::slice(2, 3, 4); - const auto a3 = std::slice(3, 3, 4); - const auto a4 = std::slice(2, 4, 4); - const auto a5 = std::slice(2, 3, 3); - - static_assert((a1 == a2) == true); - static_assert((a1 == a3) == false); - static_assert((a1 == a4) == false); - static_assert((a1 == a5) == false); + static_assert((std::slice(2, 3, 4) == std::slice(2, 3, 4)) == true); + static_assert((std::slice(2, 3, 4) == std::slice(3, 3, 4)) == false); + static_assert((std::slice(2, 3, 4) == std::slice(2, 4, 4)) == false); + static_assert((std::slice(2, 3, 4) == std::slice(2, 3, 3)) == false); } { // filesystem::space_info constexpr std::filesystem::space_info si1{4'000'000'000'000, 2'000'000'000'000, 1'000'000'000'000}; From 41de4bbd54b2b763a8b92b3799d4ec03f6f8c74a Mon Sep 17 00:00:00 2001 From: Anju del Moral Gonzalez Date: Wed, 10 Feb 2021 15:14:39 -0800 Subject: [PATCH 06/11] Update stl/inc/valarray Co-authored-by: Stephan T. Lavavej --- stl/inc/valarray | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/valarray b/stl/inc/valarray index c636855d134..29d1ab887a1 100644 --- a/stl/inc/valarray +++ b/stl/inc/valarray @@ -1374,7 +1374,7 @@ public: } #if _HAS_CXX20 - _NODISCARD friend bool operator==(const slice& _Left, const slice& _Right) const noexcept /* strengthened */ { + _NODISCARD friend bool operator==(const slice& _Left, const slice& _Right) noexcept /* strengthened */ { return _Left.start() == _Right.start() && _Left.size() == _Right.size() && _Left.stride() == _Right.stride(); } #endif // !_HAS_CXX20 From 76648b105fab29ba7462655b101540714d0e76da Mon Sep 17 00:00:00 2001 From: Anju Del Moral Gonzalez Date: Wed, 10 Feb 2021 15:16:59 -0800 Subject: [PATCH 07/11] added variables --- tests/std/tests/P1614R2_spaceship/test.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/std/tests/P1614R2_spaceship/test.cpp b/tests/std/tests/P1614R2_spaceship/test.cpp index 77613c311ed..f6992206b9d 100644 --- a/tests/std/tests/P1614R2_spaceship/test.cpp +++ b/tests/std/tests/P1614R2_spaceship/test.cpp @@ -485,10 +485,15 @@ void ordering_test_cases() { spaceship_test(c_mem[0], c_mem[0], c_mem[1]); } { // slice - static_assert((std::slice(2, 3, 4) == std::slice(2, 3, 4)) == true); - static_assert((std::slice(2, 3, 4) == std::slice(3, 3, 4)) == false); - static_assert((std::slice(2, 3, 4) == std::slice(2, 4, 4)) == false); - static_assert((std::slice(2, 3, 4) == std::slice(2, 3, 3)) == false); + std::slice a1 = std::slice(2, 3, 4); + std::slice a2 = std::slice(2, 3, 4); + std::slice a3 = std::slice(3, 3, 4); + std::slice a4 = std::slice(2, 4, 4); + std::slice a5 = std::slice(2, 3, 3); + static_assert(a1 == a2) == true); + static_assert(a1 == a3) == false); + static_assert(a1 == a4) == false); + static_assert(a1 == a5) == false); } { // filesystem::space_info constexpr std::filesystem::space_info si1{4'000'000'000'000, 2'000'000'000'000, 1'000'000'000'000}; From 6d917a76bc48c838f2248768803adced956c6105 Mon Sep 17 00:00:00 2001 From: Anju Del Moral Gonzalez Date: Wed, 10 Feb 2021 16:16:31 -0800 Subject: [PATCH 08/11] simplified expresions --- tests/std/tests/P1614R2_spaceship/test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/std/tests/P1614R2_spaceship/test.cpp b/tests/std/tests/P1614R2_spaceship/test.cpp index fcc839eea00..86e3695e4fe 100644 --- a/tests/std/tests/P1614R2_spaceship/test.cpp +++ b/tests/std/tests/P1614R2_spaceship/test.cpp @@ -490,10 +490,10 @@ void ordering_test_cases() { std::slice a3 = std::slice(3, 3, 4); std::slice a4 = std::slice(2, 4, 4); std::slice a5 = std::slice(2, 3, 3); - static_assert((a1 == a2) == true); - static_assert((a1 == a3) == false); - static_assert((a1 == a4) == false); - static_assert((a1 == a5) == false); + static_assert(a1 == a2); + static_assert(a1 != a3); + static_assert(a1 != a4); + static_assert(a1 != a5); } { // filesystem::space_info constexpr std::filesystem::space_info si1{4'000'000'000'000, 2'000'000'000'000, 1'000'000'000'000}; From cccc3285a7881005b5f7f9c817064bd092b651da Mon Sep 17 00:00:00 2001 From: Anju Del Moral Gonzalez Date: Thu, 11 Feb 2021 11:56:40 -0800 Subject: [PATCH 09/11] Changed to assert --- tests/std/tests/P1614R2_spaceship/test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/std/tests/P1614R2_spaceship/test.cpp b/tests/std/tests/P1614R2_spaceship/test.cpp index 86e3695e4fe..7ceb0fd39f5 100644 --- a/tests/std/tests/P1614R2_spaceship/test.cpp +++ b/tests/std/tests/P1614R2_spaceship/test.cpp @@ -490,10 +490,10 @@ void ordering_test_cases() { std::slice a3 = std::slice(3, 3, 4); std::slice a4 = std::slice(2, 4, 4); std::slice a5 = std::slice(2, 3, 3); - static_assert(a1 == a2); - static_assert(a1 != a3); - static_assert(a1 != a4); - static_assert(a1 != a5); + assert(a1 == a2); + assert(a1 != a3); + assert(a1 != a4); + assert(a1 != a5); } { // filesystem::space_info constexpr std::filesystem::space_info si1{4'000'000'000'000, 2'000'000'000'000, 1'000'000'000'000}; From 654af91b2a0a9f7e1f02b852370ab77eca1659cf Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Thu, 11 Feb 2021 20:01:45 -0800 Subject: [PATCH 10/11] Change comment to match #if. --- stl/inc/valarray | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/valarray b/stl/inc/valarray index 29d1ab887a1..5f5a6ab33fc 100644 --- a/stl/inc/valarray +++ b/stl/inc/valarray @@ -1377,7 +1377,7 @@ public: _NODISCARD friend bool operator==(const slice& _Left, const slice& _Right) noexcept /* strengthened */ { return _Left.start() == _Right.start() && _Left.size() == _Right.size() && _Left.stride() == _Right.stride(); } -#endif // !_HAS_CXX20 +#endif // _HAS_CXX20 protected: size_t _Start = 0; // the starting offset From 5bf4683ac820c93ba7d2beb8468f7223201ca588 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Thu, 11 Feb 2021 20:02:21 -0800 Subject: [PATCH 11/11] Directly construct slices. --- tests/std/tests/P1614R2_spaceship/test.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/std/tests/P1614R2_spaceship/test.cpp b/tests/std/tests/P1614R2_spaceship/test.cpp index 7ceb0fd39f5..1775d4b97f3 100644 --- a/tests/std/tests/P1614R2_spaceship/test.cpp +++ b/tests/std/tests/P1614R2_spaceship/test.cpp @@ -485,11 +485,11 @@ void ordering_test_cases() { spaceship_test(c_mem[0], c_mem[0], c_mem[1]); } { // slice - std::slice a1 = std::slice(2, 3, 4); - std::slice a2 = std::slice(2, 3, 4); - std::slice a3 = std::slice(3, 3, 4); - std::slice a4 = std::slice(2, 4, 4); - std::slice a5 = std::slice(2, 3, 3); + std::slice a1(2, 3, 4); + std::slice a2(2, 3, 4); + std::slice a3(3, 3, 4); + std::slice a4(2, 4, 4); + std::slice a5(2, 3, 3); assert(a1 == a2); assert(a1 != a3); assert(a1 != a4);