diff --git a/rclcpp/include/rclcpp/duration.hpp b/rclcpp/include/rclcpp/duration.hpp index eb716c3348..00aba81e78 100644 --- a/rclcpp/include/rclcpp/duration.hpp +++ b/rclcpp/include/rclcpp/duration.hpp @@ -77,6 +77,9 @@ class RCLCPP_PUBLIC Duration bool operator==(const rclcpp::Duration & rhs) const; + bool + operator!=(const rclcpp::Duration & rhs) const; + bool operator<(const rclcpp::Duration & rhs) const; diff --git a/rclcpp/src/rclcpp/duration.cpp b/rclcpp/src/rclcpp/duration.cpp index 2114ddd16f..cbe904b679 100644 --- a/rclcpp/src/rclcpp/duration.cpp +++ b/rclcpp/src/rclcpp/duration.cpp @@ -96,6 +96,12 @@ Duration::operator==(const rclcpp::Duration & rhs) const return rcl_duration_.nanoseconds == rhs.rcl_duration_.nanoseconds; } +bool +Duration::operator!=(const rclcpp::Duration & rhs) const +{ + return rcl_duration_.nanoseconds != rhs.rcl_duration_.nanoseconds; +} + bool Duration::operator<(const rclcpp::Duration & rhs) const { diff --git a/rclcpp/test/test_duration.cpp b/rclcpp/test/test_duration.cpp index b69a790d28..202358402a 100644 --- a/rclcpp/test/test_duration.cpp +++ b/rclcpp/test/test_duration.cpp @@ -45,6 +45,7 @@ TEST(TestDuration, operators) { EXPECT_TRUE(old <= young); EXPECT_TRUE(young >= old); EXPECT_FALSE(young == old); + EXPECT_TRUE(young != old); rclcpp::Duration add = old + young; EXPECT_EQ(add.nanoseconds(), old.nanoseconds() + young.nanoseconds());