Skip to content

Commit 9f24b4f

Browse files
committed
extra stable_vector fixes
1 parent ebb237a commit 9f24b4f

2 files changed

Lines changed: 20 additions & 37 deletions

File tree

mstd/include/containers/mstd/stable_vector.hpp

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -517,42 +517,36 @@ namespace mstd {
517517

518518
[[nodiscard]] const value_type* data() const { return _data.data(); }
519519

520-
[[nodiscard]] _MSTD_CONSTEXPR20 bool operator==(const stable_vector& other) const
521-
#if _MSTD_HAS_CXX20
522-
= default;
523-
#else
524-
{
520+
[[nodiscard]] _MSTD_CONSTEXPR20 bool operator==(const stable_vector& other) const {
525521
return _data == other._data && _toId == other._toId && _toData == other._toData;
526522
}
527-
#endif
528523

529-
[[nodiscard]] _MSTD_CONSTEXPR20 bool operator!=(const stable_vector& other) const
530-
#if _MSTD_HAS_CXX20
531-
= default;
532-
#else
533-
{
534-
return !(*this == other);
535-
}
536-
#endif
524+
[[nodiscard]] _MSTD_CONSTEXPR20 bool operator!=(const stable_vector& other) const { return !(*this == other); }
537525

538526
#if _MSTD_HAS_CXX20
539-
[[nodiscard]] _MSTD_CONSTEXPR20 auto operator<=>(const stable_vector& other) const = default;
540-
#else
541-
[[nodiscard]] _MSTD_CONSTEXPR20 bool operator<(const stable_vector& other) const {
542-
return _data < other._data && _toId < other._toId && _toData < other._toData;
543-
}
527+
[[nodiscard]] constexpr auto operator<=>(const stable_vector& other) const {
528+
if (auto cmp = _data <=> other._data; cmp != 0) { return cmp; }
544529

545-
[[nodiscard]] _MSTD_CONSTEXPR20 bool operator<=(const stable_vector& other) const {
546-
return _data <= other._data && _toId <= other._toId && _toData <= other._toData;
547-
}
530+
if (auto cmp = _toId <=> other._toId; cmp != 0) { return cmp; }
548531

549-
[[nodiscard]] _MSTD_CONSTEXPR20 bool operator>(const stable_vector& other) const {
550-
return _data > other._data && _toId > other._toId && _toData > other._toData;
532+
return _toData <=> other._toData;
551533
}
534+
#else
535+
[[nodiscard]] bool operator<(const stable_vector& other) const {
536+
if (_data < other._data) { return true; }
537+
if (other._data < _data) { return false; }
538+
539+
if (_toId < other._toId) { return true; }
540+
if (other._toId < _toId) { return false; }
552541

553-
[[nodiscard]] _MSTD_CONSTEXPR20 bool operator>=(const stable_vector& other) const {
554-
return _data >= other._data && _toId >= other._toId && _toData >= other._toData;
542+
return _toData < other._toData;
555543
}
544+
545+
[[nodiscard]] bool operator<=(const stable_vector& other) const { return !(other < *this); }
546+
547+
[[nodiscard]] bool operator>(const stable_vector& other) const { return other < *this; }
548+
549+
[[nodiscard]] bool operator>=(const stable_vector& other) const { return !(*this < other); }
556550
#endif
557551
};
558552
} // namespace mstd

tests/containers/stable_vector_tests.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -652,20 +652,9 @@ namespace mstd::test {
652652
mstd::stable_vector<int> c2 = { 1, 2, 4 };
653653
mstd::stable_vector<int> c3 = { 1, 2, 3, 4 };
654654

655-
#if _MSTD_HAS_CXX20
656655
EXPECT_TRUE(c1 < c2); // 3 < 4
657-
#else
658-
EXPECT_FALSE(c1 < c2);
659-
#endif
660-
661656
EXPECT_TRUE(c1 <= c2);
662-
663-
#if _MSTD_HAS_CXX20
664657
EXPECT_TRUE(c2 > c1);
665-
#else
666-
EXPECT_FALSE(c2 > c1);
667-
#endif
668-
669658
EXPECT_TRUE(c2 >= c1);
670659
EXPECT_TRUE(c1 < c3); // c1 is shorter
671660
}

0 commit comments

Comments
 (0)