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
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved

// 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
5 changes: 5 additions & 0 deletions stl/inc/valarray
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,11 @@ public:
_NODISCARD size_t stride() const noexcept /* strengthened */ {
return _Stride;
}
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
#if _HAS_CXX200
AnjuDel marked this conversation as resolved.
Show resolved Hide resolved
friend bool operator==(const slice& x, const slice& y) {
AnjuDel marked this conversation as resolved.
Show resolved Hide resolved
AnjuDel marked this conversation as resolved.
Show resolved Hide resolved
AnjuDel marked this conversation as resolved.
Show resolved Hide resolved
return x.start() == y.start() && x.size() == y.size() && x.stride() == y.stride();
}
#endif
AnjuDel marked this conversation as resolved.
Show resolved Hide resolved

protected:
size_t _Start = 0; // the starting offset
Expand Down
19 changes: 19 additions & 0 deletions tests/std/tests/P1614R2_spaceship/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <iostream>
#include <list>
#include <map>
#include <numeric>
AnjuDel marked this conversation as resolved.
Show resolved Hide resolved
#include <queue>
#include <ranges>
#include <regex>
Expand All @@ -27,6 +28,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 @@ -287,6 +289,23 @@ void ordering_test_cases() {
std::forward_list<SynthOrdered> b = {10, 20, 40};
ordered_containers_test(a, a, b);
}
{ // slice
AnjuDel marked this conversation as resolved.
Show resolved Hide resolved
std::valarray<int> a(20);
for (int i = 0; i < 12; ++i) {
AnjuDel marked this conversation as resolved.
Show resolved Hide resolved
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)];
AnjuDel marked this conversation as resolved.
Show resolved Hide resolved

static_assert((a1 == a2) == true);
static_assert((a1 == a3) == false);
static_assert((a1 == a4) == false);
static_assert((a1 == a5) == false);
}
{ // map
std::map<std::string, int> a1;
a1["hi"] = 1;
Expand Down