From 030234c7a6c7f6c5a901dab68591c9cfb2d4828f Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Sat, 3 Sep 2016 13:28:55 -0700 Subject: [core] Rework invokeWithCallback so that the callback is last --- include/mbgl/util/work_task_impl.hpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'include/mbgl/util/work_task_impl.hpp') diff --git a/include/mbgl/util/work_task_impl.hpp b/include/mbgl/util/work_task_impl.hpp index 2c016601bb..a2f55e00c5 100644 --- a/include/mbgl/util/work_task_impl.hpp +++ b/include/mbgl/util/work_task_impl.hpp @@ -62,10 +62,12 @@ std::shared_ptr WorkTask::make(Fn&& fn, Args&&... args) { flag); } -template -std::shared_ptr WorkTask::makeWithCallback(Fn&& fn, Cb&& callback, Args&&... args) { - auto flag = std::make_shared>(); - *flag = false; +namespace detail { +template +auto packageArgumentsAndCallback(std::shared_ptr> flag, + Tuple&& args, + std::index_sequence) { + auto callback = std::get(args); // Create a lambda L1 that invokes another lambda L2 on the current RunLoop R, that calls // the callback C. Both lambdas check the flag before proceeding. L1 needs to check the flag @@ -82,7 +84,19 @@ std::shared_ptr WorkTask::makeWithCallback(Fn&& fn, Cb&& callback, Arg } }; - auto tuple = std::make_tuple(std::move(args)..., after); + return std::make_tuple(std::move(std::get(args))..., after); +} +} // namespace detail + +template +std::shared_ptr WorkTask::makeWithCallback(Fn&& fn, Args&&... args) { + auto flag = std::make_shared>(); + *flag = false; + + auto tuple = detail::packageArgumentsAndCallback(flag, + std::forward_as_tuple(std::forward(args)...), + std::make_index_sequence()); + return std::make_shared>( std::move(fn), std::move(tuple), -- cgit v1.2.1