From 921783988fb81f6ef4815a38f3046233df595532 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Fri, 1 Dec 2023 09:46:09 -0500 Subject: [PATCH 1/5] remove friend identifier and define the + and - operator outside of class --- libs/libvtrutil/src/vtr_strong_id_range.h | 52 +++++++++++------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/libs/libvtrutil/src/vtr_strong_id_range.h b/libs/libvtrutil/src/vtr_strong_id_range.h index e9fd938f3d6..d19ef07e1e9 100644 --- a/libs/libvtrutil/src/vtr_strong_id_range.h +++ b/libs/libvtrutil/src/vtr_strong_id_range.h @@ -88,26 +88,6 @@ class StrongIdIterator { return StrongId(size_t(id_) + offset); } - ///@brief + operator - template - friend StrongIdIterator operator+( - const StrongIdIterator& lhs, - ssize_t n) { - StrongIdIterator ret = lhs; - ret += n; - return ret; - } - - ///@brief - operator - template - friend StrongIdIterator operator-( - const StrongIdIterator& lhs, - ssize_t n) { - StrongIdIterator ret = lhs; - ret -= n; - return ret; - } - ///@brief ~ operator template friend ssize_t operator-( @@ -123,26 +103,46 @@ class StrongIdIterator { ///@brief == operator template - friend bool operator==(const StrongIdIterator& lhs, const StrongIdIterator& rhs) { - return lhs.id_ == rhs.id_; + bool operator==(const StrongIdIterator& other) { + return id_ == other.id_; } ///@brief != operator template - friend bool operator!=(const StrongIdIterator& lhs, const StrongIdIterator& rhs) { - return lhs.id_ != rhs.id_; + bool operator!=(const StrongIdIterator& other) { + return id_ != other.id_; } ///@brief < operator template - friend bool operator<(const StrongIdIterator& lhs, const StrongIdIterator& rhs) { - return lhs.id_ < rhs.id_; + bool operator<(const StrongIdIterator& other) { + return id_ < other.id_; } private: StrongId id_; }; +///@brief + operator +template +inline StrongIdIterator operator+( + const StrongIdIterator& lhs, + ssize_t n) { + StrongIdIterator ret = lhs; + ret += n; + return ret; +} + +///@brief - operator +template +inline StrongIdIterator operator-( + const StrongIdIterator& lhs, + ssize_t n) { + StrongIdIterator ret = lhs; + ret -= n; + return ret; +} + /** * @brief StrongIdRange class * From 7c1d3dd9914e66d57f3b71de9e60814039fb2d82 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Fri, 1 Dec 2023 10:04:54 -0500 Subject: [PATCH 2/5] remove friend identifier from - operand --- libs/libvtrutil/src/vtr_strong_id_range.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/libs/libvtrutil/src/vtr_strong_id_range.h b/libs/libvtrutil/src/vtr_strong_id_range.h index d19ef07e1e9..1c5d06fc948 100644 --- a/libs/libvtrutil/src/vtr_strong_id_range.h +++ b/libs/libvtrutil/src/vtr_strong_id_range.h @@ -90,14 +90,12 @@ class StrongIdIterator { ///@brief ~ operator template - friend ssize_t operator-( - const StrongIdIterator& lhs, - const StrongIdIterator& rhs) { - VTR_ASSERT_SAFE(bool(lhs.id_)); - VTR_ASSERT_SAFE(bool(rhs.id_)); - - ssize_t ret = size_t(lhs.id_); - ret -= size_t(rhs.id_); + ssize_t operator-(const StrongIdIterator& other) { + VTR_ASSERT_SAFE(bool(id_)); + VTR_ASSERT_SAFE(bool(other.id_)); + + ssize_t ret = size_t(id_); + ret -= size_t(other.id_); return ret; } From ee0a6d617f78c0eab4128e0499efbdec2574ef24 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Fri, 1 Dec 2023 12:31:07 -0500 Subject: [PATCH 3/5] catch2: change the order of variables in assignment --- libs/libvtrutil/test/test_strong_id.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/libvtrutil/test/test_strong_id.cpp b/libs/libvtrutil/test/test_strong_id.cpp index d9b766a1710..bc0f83aeddd 100644 --- a/libs/libvtrutil/test/test_strong_id.cpp +++ b/libs/libvtrutil/test/test_strong_id.cpp @@ -82,7 +82,7 @@ TEST_CASE("StrongIdIterator", "[StrongId/StrongIdIterator]") { REQUIRE(c_iter[-4] == b); REQUIRE(c_iter[-5] == a); - REQUIRE((a_iter + 5) == c_iter); + REQUIRE(c_iter == (a_iter + 5)); REQUIRE(a_iter == (c_iter - 5)); a_iter += 5; REQUIRE(a_iter == c_iter); From c0ed00595e7629db67dfb967e7a16d64696f5bd9 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Fri, 1 Dec 2023 17:37:52 -0500 Subject: [PATCH 4/5] add const identifier for strong id range operators --- libs/libvtrutil/src/vtr_strong_id_range.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/libvtrutil/src/vtr_strong_id_range.h b/libs/libvtrutil/src/vtr_strong_id_range.h index 1c5d06fc948..f22df41f67e 100644 --- a/libs/libvtrutil/src/vtr_strong_id_range.h +++ b/libs/libvtrutil/src/vtr_strong_id_range.h @@ -90,7 +90,7 @@ class StrongIdIterator { ///@brief ~ operator template - ssize_t operator-(const StrongIdIterator& other) { + ssize_t operator-(const StrongIdIterator& other) const { VTR_ASSERT_SAFE(bool(id_)); VTR_ASSERT_SAFE(bool(other.id_)); @@ -101,19 +101,19 @@ class StrongIdIterator { ///@brief == operator template - bool operator==(const StrongIdIterator& other) { + bool operator==(const StrongIdIterator& other) const { return id_ == other.id_; } ///@brief != operator template - bool operator!=(const StrongIdIterator& other) { + bool operator!=(const StrongIdIterator& other) const { return id_ != other.id_; } ///@brief < operator template - bool operator<(const StrongIdIterator& other) { + bool operator<(const StrongIdIterator& other) const { return id_ < other.id_; } From a1179350705c81af7e35419dbf3305beb13dcddd Mon Sep 17 00:00:00 2001 From: amin1377 Date: Fri, 1 Dec 2023 17:42:31 -0500 Subject: [PATCH 5/5] restore the order of test --- libs/libvtrutil/test/test_strong_id.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/libvtrutil/test/test_strong_id.cpp b/libs/libvtrutil/test/test_strong_id.cpp index bc0f83aeddd..d9b766a1710 100644 --- a/libs/libvtrutil/test/test_strong_id.cpp +++ b/libs/libvtrutil/test/test_strong_id.cpp @@ -82,7 +82,7 @@ TEST_CASE("StrongIdIterator", "[StrongId/StrongIdIterator]") { REQUIRE(c_iter[-4] == b); REQUIRE(c_iter[-5] == a); - REQUIRE(c_iter == (a_iter + 5)); + REQUIRE((a_iter + 5) == c_iter); REQUIRE(a_iter == (c_iter - 5)); a_iter += 5; REQUIRE(a_iter == c_iter);