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 * bjam use clang on MACOSX
* Simplify Travis package install specification * 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. /** Mix-in to support tests using asio coroutines.
Derive from this class and use yield_to to launch test functions Derive from this class and use yield_to to launch test
inside coroutines. This is handy for testing asynchronous asio functions inside coroutines. This is handy for testing
code. asynchronous asio code.
*/ */
class enable_yield_to class enable_yield_to
{ {
@ -72,12 +72,32 @@ public:
Function will be called with this signature: Function will be called with this signature:
@code @code
void f(yield_context); void f(args..., yield_context);
@endcode @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 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> template<class Function>

View File

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

View File

@ -378,17 +378,10 @@ public:
{ {
testThrow(); testThrow();
yield_to(std::bind(&read_test::testFailures, yield_to(&read_test::testFailures, this);
this, std::placeholders::_1)); yield_to(&read_test::testReadHeaders, this);
yield_to(&read_test::testRead, this);
yield_to(std::bind(&read_test::testReadHeaders, yield_to(&read_test::testEof, this);
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));
} }
}; };

View File

@ -702,12 +702,9 @@ public:
void run() override void run() override
{ {
yield_to(std::bind(&write_test::testAsyncWriteHeaders, yield_to(&write_test::testAsyncWriteHeaders, this);
this, std::placeholders::_1)); yield_to(&write_test::testAsyncWrite, this);
yield_to(std::bind(&write_test::testAsyncWrite, yield_to(&write_test::testFailures, this);
this, std::placeholders::_1));
yield_to(std::bind(&write_test::testFailures,
this, std::placeholders::_1));
testOutput(); testOutput();
test_std_ostream(); test_std_ostream();
testOstream(); testOstream();