From c594bbac3f99b278b3889fe062e86d15fa76015b Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Thu, 19 Jan 2017 12:05:56 -0500 Subject: [PATCH] Add optional yield_to arguments --- CHANGELOG.md | 1 + extras/beast/test/yield_to.hpp | 32 ++++++++++++++++++++++++++------ test/core/dynabuf_readstream.cpp | 3 +-- test/http/read.cpp | 15 ++++----------- test/http/write.cpp | 9 +++------ 5 files changed, 35 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d27fea1..5b62cf34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * bjam use clang on MACOSX * Simplify Travis package install specification +* Add optional yield_to arguments -------------------------------------------------------------------------------- diff --git a/extras/beast/test/yield_to.hpp b/extras/beast/test/yield_to.hpp index 5c4d3c01..fecd8d4b 100644 --- a/extras/beast/test/yield_to.hpp +++ b/extras/beast/test/yield_to.hpp @@ -21,9 +21,9 @@ namespace test { /** Mix-in to support tests using asio coroutines. - Derive from this class and use yield_to to launch test functions - inside coroutines. This is handy for testing asynchronous asio - code. + Derive from this class and use yield_to to launch test + functions inside coroutines. This is handy for testing + asynchronous asio code. */ class enable_yield_to { @@ -72,12 +72,32 @@ public: Function will be called with this signature: @code - void f(yield_context); + void f(args..., yield_context); @endcode + + @param f The Callable object to invoke. + + @param args Optional arguments forwarded to the callable object. */ - template +#if GENERATING_DOCS + template void - yield_to(Function&& f); + yield_to(F&& f, Args&&... args); +#else + template + void + yield_to(F&& f); + + template + void + yield_to(Function&& f, Arg&& arg, Args&&... args) + { + yield_to(std::bind(f, + std::forward(arg), + std::forward(args)..., + std::placeholders::_1)); + } +#endif }; template diff --git a/test/core/dynabuf_readstream.cpp b/test/core/dynabuf_readstream.cpp index a2ff8bc5..59e40498 100644 --- a/test/core/dynabuf_readstream.cpp +++ b/test/core/dynabuf_readstream.cpp @@ -132,8 +132,7 @@ public: { testSpecialMembers(); - yield_to(std::bind(&self::testRead, - this, std::placeholders::_1)); + yield_to(&self::testRead, this); } }; diff --git a/test/http/read.cpp b/test/http/read.cpp index 8775dc2f..bce7a86e 100644 --- a/test/http/read.cpp +++ b/test/http/read.cpp @@ -378,17 +378,10 @@ public: { testThrow(); - yield_to(std::bind(&read_test::testFailures, - this, std::placeholders::_1)); - - yield_to(std::bind(&read_test::testReadHeaders, - this, std::placeholders::_1)); - - yield_to(std::bind(&read_test::testRead, - this, std::placeholders::_1)); - - yield_to(std::bind(&read_test::testEof, - this, std::placeholders::_1)); + yield_to(&read_test::testFailures, this); + yield_to(&read_test::testReadHeaders, this); + yield_to(&read_test::testRead, this); + yield_to(&read_test::testEof, this); } }; diff --git a/test/http/write.cpp b/test/http/write.cpp index 514086d3..09a087b3 100644 --- a/test/http/write.cpp +++ b/test/http/write.cpp @@ -702,12 +702,9 @@ public: void run() override { - yield_to(std::bind(&write_test::testAsyncWriteHeaders, - this, std::placeholders::_1)); - yield_to(std::bind(&write_test::testAsyncWrite, - this, std::placeholders::_1)); - yield_to(std::bind(&write_test::testFailures, - this, std::placeholders::_1)); + yield_to(&write_test::testAsyncWriteHeaders, this); + yield_to(&write_test::testAsyncWrite, this); + yield_to(&write_test::testFailures, this); testOutput(); test_std_ostream(); testOstream();