Finish the partial callback application feature

This commit is contained in:
Denis Blank 2017-02-28 22:45:46 +01:00
parent 3b4fd82039
commit 28b1d57abb
3 changed files with 22 additions and 4 deletions

View File

@ -253,7 +253,7 @@ Continuables returning more then one value will evaluate to a future providing a
Although the library has progressed very far there are still some candies missing:
- [ ] **Partial application**:
- [x] **Partial application**:
We could allow callbacks to be invoked with fewer arguments than expected:

View File

@ -865,17 +865,24 @@ auto chain_continuation(Continuation&& continuation, Callback&& callback,
static_assert(is_continuation<std::decay_t<Continuation>>{},
"Expected a continuation!");
// Wrap the callback into a partial callable callback
auto partial_callable = [callback = std::forward<Callback>(callback)](
auto&&... args) mutable {
return util::partial_invoke(std::move(callback),
std::forward<decltype(args)>(args)...);
};
auto hint = hint_of(util::identity_of(continuation));
auto next_hint = next_hint_of(util::identity_of(callback), hint);
auto next_hint = next_hint_of(util::identity_of(partial_callable), hint);
return make_continuable_base(
[
continuation = std::forward<Continuation>(continuation),
callback = std::forward<Callback>(callback),
partial_callable = std::move(partial_callable),
executor = std::forward<Executor>(executor)
](auto&& nextCallback) mutable {
invoke_proxy(hint_of(util::identity_of(continuation)),
std::move(continuation), std::move(callback),
std::move(continuation), std::move(partial_callable),
std::move(executor),
std::forward<decltype(nextCallback)>(nextCallback));
},

View File

@ -127,3 +127,14 @@ TYPED_TEST(single_dimension_tests, are_executable_through_dispatchers) {
EXPECT_EQ(future.get(), canary);
}
}
TYPED_TEST(single_dimension_tests, are_partial_callable) {
EXPECT_ASYNC_RESULT(this->supply(1, 2).then([] {
// ...
}));
EXPECT_ASYNC_RESULT(this->supply(0xDF, 0xDD, 3, 4).then([](int a, int b) {
EXPECT_EQ(a, 0xDF);
EXPECT_EQ(b, 0xDD);
}));
}