Skip to content

Commit

Permalink
feature/spaceship: Clause 26: Numerics (#1627)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephan T. Lavavej <[email protected]>
  • Loading branch information
Anju del Moral Gonzalez and StephanTLavavej authored Feb 12, 2021
1 parent e68b14a commit 5443c4a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
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;
}

#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>

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

0 comments on commit 5443c4a

Please sign in to comment.