diff --git a/include/boost/asio/defer.hpp b/include/boost/asio/defer.hpp index 8bf0477a..d9489e23 100644 --- a/include/boost/asio/defer.hpp +++ b/include/boost/asio/defer.hpp @@ -80,8 +80,8 @@ namespace asio { * @par Completion Signature * @code void() @endcode */ -template -inline auto defer(NullaryToken&& token) +template +inline auto defer(NullaryToken&& token = deferred_t()) -> decltype( async_initiate( declval(), token)) diff --git a/include/boost/asio/dispatch.hpp b/include/boost/asio/dispatch.hpp index 62dcfef5..8e4d0960 100644 --- a/include/boost/asio/dispatch.hpp +++ b/include/boost/asio/dispatch.hpp @@ -70,8 +70,8 @@ namespace asio { * @par Completion Signature * @code void() @endcode */ -template -inline auto dispatch(NullaryToken&& token) +template +inline auto dispatch(NullaryToken&& token = deferred_t()) -> decltype( async_initiate( declval(), token)) diff --git a/include/boost/asio/post.hpp b/include/boost/asio/post.hpp index 0ceadc05..c5f8cdc5 100644 --- a/include/boost/asio/post.hpp +++ b/include/boost/asio/post.hpp @@ -78,8 +78,8 @@ namespace asio { * @par Completion Signature * @code void() @endcode */ -template -inline auto post(NullaryToken&& token) +template +inline auto post(NullaryToken&& token = deferred_t()) -> decltype( async_initiate( declval(), token)) diff --git a/test/defer.cpp b/test/defer.cpp index 170ad3c2..579e12d7 100644 --- a/test/defer.cpp +++ b/test/defer.cpp @@ -16,6 +16,7 @@ // Test that header file is self-contained. #include +#include #include #include "unit_test.hpp" @@ -95,6 +96,22 @@ void move_only_result_handler( *result_out = result_in.value(); } +void defer_no_args_test() +{ + io_context ctx(1); + + int handler_count = 0; + boost::asio::defer(boost::asio::deferred)( + boost::asio::bind_executor(ctx, + bindns::bind(void_handler, &handler_count))); + + BOOST_ASIO_CHECK(handler_count == 0); + + ctx.run(); + + BOOST_ASIO_CHECK(handler_count == 1); +} + void defer_function_test() { io_context ctx(1); @@ -229,5 +246,6 @@ void defer_function_test() BOOST_ASIO_TEST_SUITE ( "defer", + BOOST_ASIO_TEST_CASE(defer_no_args_test) BOOST_ASIO_TEST_CASE(defer_function_test) ) diff --git a/test/dispatch.cpp b/test/dispatch.cpp index 61336a13..57aff4e0 100644 --- a/test/dispatch.cpp +++ b/test/dispatch.cpp @@ -16,6 +16,7 @@ // Test that header file is self-contained. #include +#include #include #include "unit_test.hpp" @@ -95,6 +96,22 @@ void move_only_result_handler( *result_out = result_in.value(); } +void dispatch_no_args_test() +{ + io_context ctx(1); + + int handler_count = 0; + boost::asio::dispatch(boost::asio::deferred)( + boost::asio::bind_executor(ctx, + bindns::bind(void_handler, &handler_count))); + + BOOST_ASIO_CHECK(handler_count == 0); + + ctx.run(); + + BOOST_ASIO_CHECK(handler_count == 1); +} + void dispatch_function_test() { io_context ctx(1); @@ -229,5 +246,6 @@ void dispatch_function_test() BOOST_ASIO_TEST_SUITE ( "dispatch", + BOOST_ASIO_TEST_CASE(dispatch_no_args_test) BOOST_ASIO_TEST_CASE(dispatch_function_test) ) diff --git a/test/post.cpp b/test/post.cpp index ea86795a..5c58dcff 100644 --- a/test/post.cpp +++ b/test/post.cpp @@ -16,6 +16,7 @@ // Test that header file is self-contained. #include +#include #include #include "unit_test.hpp" @@ -95,6 +96,22 @@ void move_only_result_handler( *result_out = result_in.value(); } +void post_no_args_test() +{ + io_context ctx(1); + + int handler_count = 0; + boost::asio::post(boost::asio::deferred)( + boost::asio::bind_executor(ctx, + bindns::bind(void_handler, &handler_count))); + + BOOST_ASIO_CHECK(handler_count == 0); + + ctx.run(); + + BOOST_ASIO_CHECK(handler_count == 1); +} + void post_function_test() { io_context ctx(1); @@ -229,5 +246,6 @@ void post_function_test() BOOST_ASIO_TEST_SUITE ( "post", + BOOST_ASIO_TEST_CASE(post_no_args_test) BOOST_ASIO_TEST_CASE(post_function_test) )