Add optional yield_to arguments

This commit is contained in:
Vinnie Falco
2017-01-19 12:05:56 -05:00
parent 6840f5840f
commit c594bbac3f
5 changed files with 35 additions and 25 deletions

View File

@ -2,6 +2,7 @@
* bjam use clang on MACOSX
* Simplify Travis package install specification
* Add optional yield_to arguments
--------------------------------------------------------------------------------

View File

@ -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<class Function>
#if GENERATING_DOCS
template<class F, class... Args>
void
yield_to(Function&& f);
yield_to(F&& f, Args&&... args);
#else
template<class F>
void
yield_to(F&& f);
template<class Function, class Arg, class... Args>
void
yield_to(Function&& f, Arg&& arg, Args&&... args)
{
yield_to(std::bind(f,
std::forward<Arg>(arg),
std::forward<Args>(args)...,
std::placeholders::_1));
}
#endif
};
template<class Function>

View File

@ -132,8 +132,7 @@ public:
{
testSpecialMembers();
yield_to(std::bind(&self::testRead,
this, std::placeholders::_1));
yield_to(&self::testRead, this);
}
};

View File

@ -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);
}
};

View File

@ -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();