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

Rule of five: implement move operators #2434

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions rclcpp/include/rclcpp/time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class Time
RCLCPP_PUBLIC
Time(const Time & rhs);

/// Move constructor
RCLCPP_PUBLIC
Time(Time && rhs) noexcept;

/// Time constructor
/**
* \param time_msg builtin_interfaces time message to copy
Expand Down Expand Up @@ -84,6 +88,7 @@ class Time
operator builtin_interfaces::msg::Time() const;

/**
* Copy assignment operator
* \throws std::runtime_error if seconds are negative
*/
RCLCPP_PUBLIC
Expand All @@ -100,6 +105,13 @@ class Time
Time &
operator=(const builtin_interfaces::msg::Time & time_msg);

/**
* Move assignment operator
*/
RCLCPP_PUBLIC
Time &
operator=(Time && rhs) noexcept;

/**
* \throws std::runtime_error if the time sources are different
*/
Expand Down
9 changes: 6 additions & 3 deletions rclcpp/src/rclcpp/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ Time::Time(int64_t nanoseconds, rcl_clock_type_t clock_type)

Time::Time(const Time & rhs) = default;

Time::Time(Time && rhs) noexcept = default;

Time::Time(
const builtin_interfaces::msg::Time & time_msg,
rcl_clock_type_t clock_type)
Expand All @@ -84,9 +86,7 @@ Time::Time(const rcl_time_point_t & time_point)
// noop
}

Time::~Time()
{
}
Time::~Time() = default;

Time::operator builtin_interfaces::msg::Time() const
{
Expand All @@ -103,6 +103,9 @@ Time::operator=(const builtin_interfaces::msg::Time & time_msg)
return *this;
}

Time &
operator=(Time && rhs) noexcept = default;

bool
Time::operator==(const rclcpp::Time & rhs) const
{
Expand Down