workaround limitations of moving std::function<void()>
This commit is contained in:
+24
-1
@@ -63,6 +63,29 @@ void test_call()
|
||||
testFail("Caught wrong exception : %s \"%s\"", typeid(e).name(), e.what());
|
||||
}
|
||||
|
||||
{
|
||||
testDiag("Demonstrate exclusive ownership transfer");
|
||||
bool called = false;
|
||||
std::unique_ptr<int> ival{new int(42)};
|
||||
base.call(std::bind([&called](std::unique_ptr<int>& ival) {
|
||||
auto trash(std::move(ival));
|
||||
called = true;
|
||||
}, std::move(ival)));
|
||||
testTrue(called);
|
||||
}
|
||||
|
||||
{
|
||||
testDiag("Demonstrate shared ownership transfer");
|
||||
bool called = false;
|
||||
auto ival(std::make_shared<int>(42));
|
||||
base.call(std::bind([&called](std::shared_ptr<int>& ival) {
|
||||
auto trash(std::move(ival));
|
||||
testEq(trash.use_count(), 1u);
|
||||
called = true;
|
||||
}, std::move(ival)));
|
||||
testTrue(called);
|
||||
}
|
||||
|
||||
auto internal(base.internal());
|
||||
base = evbase();
|
||||
// loop stopped
|
||||
@@ -124,7 +147,7 @@ void test_fill_evbuf()
|
||||
MAIN(testev)
|
||||
{
|
||||
SockAttach attach;
|
||||
testPlan(17);
|
||||
testPlan(20);
|
||||
testSetup();
|
||||
test_call();
|
||||
test_fill_evbuf();
|
||||
|
||||
Reference in New Issue
Block a user