workaround limitations of moving std::function<void()>

This commit is contained in:
Michael Davidsaver
2021-01-01 09:46:52 -08:00
parent bd6fb00dd5
commit bcc46f0389
3 changed files with 93 additions and 12 deletions
+24 -1
View File
@@ -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();