From 4570c29d8a6d53bbde69c7641545c6ae28933b8e Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Mon, 14 Dec 2015 20:47:35 +0100 Subject: [PATCH] decay-copy deferred callable --- include/boost/fiber/context.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/boost/fiber/context.hpp b/include/boost/fiber/context.hpp index 906f793c..b060398a 100644 --- a/include/boost/fiber/context.hpp +++ b/include/boost/fiber/context.hpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -313,12 +314,14 @@ public: use_count_{ 1 }, // fiber instance or scheduler owner flags_{ flag_worker_context }, #if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS) - ctx_{ create_( palloc, salloc, std::forward< Fn >( fn), std::make_tuple( std::forward< Args >( args) ... ) ) } + ctx_{ create_( palloc, salloc, + std::forward< Fn >( fn), + std::make_tuple( detail::decay_copy( std::forward< Args >( args) ) ... ) ) } #else ctx_{ std::allocator_arg, palloc, salloc, // mutable: generated operator() is not const -> enables std::move( fn) // std::make_tuple: stores decayed copies of its args, implicitly unwraps std::reference_wrapper - [this,fn_=std::forward< Fn >( fn),tpl_=std::make_tuple( std::forward< Args >( args) ...), + [this,fn_=detail::decay_copy( std::forward< Fn >( fn) ),tpl_=std::make_tuple( detail::decay_copy( std::forward< Args >( args) ) ...), ctx=boost::context::execution_context::current()] (void * vp) mutable noexcept { try { auto fn = std::move( fn_);