Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/spaceship: Clause 26: Numerics #1627

Merged
merged 12 commits into from
Feb 12, 2021
4 changes: 4 additions & 0 deletions stl/inc/complex
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class _Ty>
_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 <class _Ty>
_NODISCARD constexpr bool operator!=(const complex<_Ty>& _Left, const complex<_Ty>& _Right) {
return !(_Left == _Right);
Expand All @@ -1534,6 +1537,7 @@ template <class _Ty>
_NODISCARD constexpr bool operator!=(const _Ty& _Left, const complex<_Ty>& _Right) {
return !(_Left == _Right);
}
#endif // !_HAS_CXX20

// FUNCTION TEMPLATE imag
template <class _Ty>
Expand Down
6 changes: 6 additions & 0 deletions stl/inc/valarray
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,12 @@ public:
return _Stride;
}
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved

#if _HAS_CXX20
_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

protected:
size_t _Start = 0; // the starting offset
size_t _Len = 0; // the number of elements
Expand Down
12 changes: 12 additions & 0 deletions tests/std/tests/P1614R2_spaceship/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>

AnjuDel marked this conversation as resolved.
Show resolved Hide resolved
template <class T>
Expand Down Expand Up @@ -483,6 +484,17 @@ void ordering_test_cases() {

spaceship_test<std::strong_ordering>(c_mem[0], c_mem[0], c_mem[1]);
}
{ // slice
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);
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};
constexpr std::filesystem::space_info si2{4'000'000'000'000, 2'000'000'000'000, 1'000'000'000'000};
Expand Down