[QUEUED scylla next] test: change some internal comparators to std::strong_ordering

0 views
Skip to first unread message

Commit Bot

unread,
Jul 29, 2021, 3:44:31 PMJul 29
to scylla...@googlegroups.com, Avi Kivity
From: Avi Kivity <a...@scylladb.com>
Committer: Avi Kivity <a...@scylladb.com>
Branch: next

test: change some internal comparators to std::strong_ordering

Ref #1449.

---
diff --git a/test/boost/nonwrapping_range_test.cc b/test/boost/nonwrapping_range_test.cc
--- a/test/boost/nonwrapping_range_test.cc
+++ b/test/boost/nonwrapping_range_test.cc
@@ -100,7 +100,7 @@ BOOST_AUTO_TEST_CASE(test_range_with_equal_value_but_opposite_inclusiveness_is_a
}

BOOST_AUTO_TEST_CASE(test_range_contains) {
- auto cmp = [] (int i1, int i2) -> int { return i1 - i2; };
+ auto cmp = [] (int i1, int i2) -> std::strong_ordering { return i1 <=> i2; };

auto check_contains = [&] (nonwrapping_range<int> enclosing, nonwrapping_range<int> enclosed) {
BOOST_REQUIRE(enclosing.contains(enclosed, cmp));
@@ -145,7 +145,7 @@ BOOST_AUTO_TEST_CASE(test_range_contains) {
}

BOOST_AUTO_TEST_CASE(test_range_subtract) {
- auto cmp = [] (int i1, int i2) -> int { return i1 - i2; };
+ auto cmp = [] (int i1, int i2) -> std::strong_ordering { return i1 <=> i2; };
using r = nonwrapping_range<int>;
using vec = std::vector<r>;

@@ -188,8 +188,8 @@ BOOST_AUTO_TEST_CASE(test_range_subtract) {
}

struct unsigned_comparator {
- int operator()(unsigned u1, unsigned u2) const {
- return (u1 > u2 ? 1 : (u1 == u2 ? 0 : -1));
+ std::strong_ordering operator()(unsigned u1, unsigned u2) const {
+ return u1 <=> u2;
}
};

diff --git a/test/boost/range_test.cc b/test/boost/range_test.cc
--- a/test/boost/range_test.cc
+++ b/test/boost/range_test.cc
@@ -106,7 +106,7 @@ BOOST_AUTO_TEST_CASE(test_range_with_positions_within_the_same_token) {
}

BOOST_AUTO_TEST_CASE(test_range_contains) {
- auto cmp = [] (int i1, int i2) -> int { return i1 - i2; };
+ auto cmp = [] (int i1, int i2) -> std::strong_ordering { return i1 <=> i2; };

auto check_contains = [&] (range<int> enclosing, range<int> enclosed) {
BOOST_REQUIRE(enclosing.contains(enclosed, cmp));
@@ -165,7 +165,7 @@ BOOST_AUTO_TEST_CASE(test_range_contains) {
}

BOOST_AUTO_TEST_CASE(test_range_subtract) {
- auto cmp = [] (int i1, int i2) -> int { return i1 - i2; };
+ auto cmp = [] (int i1, int i2) -> std::strong_ordering { return i1 <=> i2; };
using r = range<int>;
using vec = std::vector<r>;

@@ -216,8 +216,8 @@ BOOST_AUTO_TEST_CASE(test_range_subtract) {
}

struct unsigned_comparator {
- int operator()(unsigned u1, unsigned u2) const {
- return (u1 > u2 ? 1 : (u1 == u2 ? 0 : -1));
+ std::strong_ordering operator()(unsigned u1, unsigned u2) const {
+ return u1 <=> u2;
}
};

diff --git a/test/perf/perf_collection.cc b/test/perf/perf_collection.cc
--- a/test/perf/perf_collection.cc
+++ b/test/perf/perf_collection.cc
@@ -34,14 +34,8 @@ struct key_compare {
};

struct key_tri_compare {
- int operator()(const per_key_t& a, const per_key_t& b) const noexcept {
- if (a > b) {
- return 1;
- } else if (a < b) {
- return -1;
- } else {
- return 0;
- }
+ std::strong_ordering operator()(const per_key_t& a, const per_key_t& b) const noexcept {
+ return a <=> b;
}
};

diff --git a/test/perf/perf_fast_forward.cc b/test/perf/perf_fast_forward.cc
--- a/test/perf/perf_fast_forward.cc
+++ b/test/perf/perf_fast_forward.cc
@@ -1198,7 +1198,7 @@ static unsigned cardinality(std::optional<int_range> ropt) {

static std::optional<int_range> intersection(int_range a, int_range b) {
auto int_tri_cmp = [] (int x, int y) {
- return x < y ? -1 : (x > y ? 1 : 0);
+ return x <=> y;
};
return a.intersection(b, int_tri_cmp);
}

Commit Bot

unread,
Jul 29, 2021, 9:40:19 PMJul 29
to scylla...@googlegroups.com, Avi Kivity
From: Avi Kivity <a...@scylladb.com>
Committer: Avi Kivity <a...@scylladb.com>
Branch: master
Reply all
Reply to author
Forward
0 new messages