Add move support for deadline_timer.
diff --git a/asio/include/asio/basic_deadline_timer.hpp b/asio/include/asio/basic_deadline_timer.hpp
index 8779bac..085c8ee 100644
--- a/asio/include/asio/basic_deadline_timer.hpp
+++ b/asio/include/asio/basic_deadline_timer.hpp
@@ -198,6 +198,40 @@
asio::detail::throw_error(ec, "expires_from_now");
}
+#if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
+ /// Move-construct a basic_deadline_timer from another.
+ /**
+ * This constructor moves a timer from one object to another.
+ *
+ * @param other The other basic_deadline_timer object from which the move will
+ * occur.
+ *
+ * @note Following the move, the moved-from object is in the same state as if
+ * constructed using the @c basic_deadline_timer(io_context&) constructor.
+ */
+ basic_deadline_timer(basic_deadline_timer&& other)
+ : basic_io_object<ASIO_SVC_T>(std::move(other))
+ {
+ }
+
+ /// Move-assign a basic_deadline_timer from another.
+ /**
+ * This assignment operator moves a timer from one object to another. Cancels
+ * any outstanding asynchronous operations associated with the target object.
+ *
+ * @param other The other basic_deadline_timer object from which the move will
+ * occur.
+ *
+ * @note Following the move, the moved-from object is in the same state as if
+ * constructed using the @c basic_deadline_timer(io_context&) constructor.
+ */
+ basic_deadline_timer& operator=(basic_deadline_timer&& other)
+ {
+ basic_io_object<ASIO_SVC_T>::operator=(std::move(other));
+ return *this;
+ }
+#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
+
/// Destroys the timer.
/**
* This function destroys the timer, cancelling any outstanding asynchronous
diff --git a/asio/include/asio/detail/impl/timer_queue_ptime.ipp b/asio/include/asio/detail/impl/timer_queue_ptime.ipp
index 7abe071..10c4295 100644
--- a/asio/include/asio/detail/impl/timer_queue_ptime.ipp
+++ b/asio/include/asio/detail/impl/timer_queue_ptime.ipp
@@ -75,6 +75,12 @@
return impl_.cancel_timer(timer, ops, max_cancelled);
}
+void timer_queue<time_traits<boost::posix_time::ptime> >::move_timer(
+ per_timer_data& target, per_timer_data& source)
+{
+ impl_.move_timer(target, source);
+}
+
} // namespace detail
} // namespace asio
diff --git a/asio/include/asio/detail/timer_queue_ptime.hpp b/asio/include/asio/detail/timer_queue_ptime.hpp
index 6a864e8..9d3cb7d 100644
--- a/asio/include/asio/detail/timer_queue_ptime.hpp
+++ b/asio/include/asio/detail/timer_queue_ptime.hpp
@@ -77,6 +77,10 @@
per_timer_data& timer, op_queue<operation>& ops,
std::size_t max_cancelled = (std::numeric_limits<std::size_t>::max)());
+ // Move operations from one timer to another, empty timer.
+ ASIO_DECL void move_timer(per_timer_data& target,
+ per_timer_data& source);
+
private:
timer_queue<forwarding_posix_time_traits> impl_;
};
diff --git a/asio/src/tests/unit/deadline_timer.cpp b/asio/src/tests/unit/deadline_timer.cpp
index 1b6e44a..9c48b62 100644
--- a/asio/src/tests/unit/deadline_timer.cpp
+++ b/asio/src/tests/unit/deadline_timer.cpp
@@ -340,6 +340,39 @@
ioc.run();
}
+#if defined(ASIO_HAS_MOVE)
+asio::deadline_timer make_timer(asio::io_context& ioc, int* count)
+{
+ asio::deadline_timer t(ioc);
+ t.expires_from_now(boost::posix_time::seconds(1));
+ t.async_wait(boost::bind(increment, count));
+ return t;
+}
+#endif // defined(ASIO_HAS_MOVE)
+
+void deadline_timer_move_test()
+{
+#if defined(ASIO_HAS_MOVE)
+ asio::io_context io_context1;
+ asio::io_context io_context2;
+ int count = 0;
+
+ asio::deadline_timer t1 = make_timer(io_context1, &count);
+ asio::deadline_timer t2 = make_timer(io_context2, &count);
+ asio::deadline_timer t3 = std::move(t1);
+
+ t2 = std::move(t1);
+
+ io_context2.run();
+
+ ASIO_CHECK(count == 1);
+
+ io_context1.run();
+
+ ASIO_CHECK(count == 2);
+#endif // defined(ASIO_HAS_MOVE)
+}
+
ASIO_TEST_SUITE
(
"deadline_timer",
@@ -348,6 +381,7 @@
ASIO_TEST_CASE(deadline_timer_custom_allocation_test)
ASIO_TEST_CASE(deadline_timer_thread_test)
ASIO_TEST_CASE(deadline_timer_async_result_test)
+ ASIO_TEST_CASE(deadline_timer_move_test)
)
#else // defined(ASIO_HAS_BOOST_DATE_TIME)
ASIO_TEST_SUITE