From bc5018e5de07ff36ff797f4023fab078df3bf80d Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Thu, 19 Nov 2020 09:35:48 +0100 Subject: [PATCH] Variables captured by copy are constant and cannot be std::move'd. Try to fix with C++14 generalized lambda capture and 'mutable' specifier. --- include/simgrid/s4u/Engine.hpp | 4 ++-- src/s4u/s4u_Engine.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/simgrid/s4u/Engine.hpp b/include/simgrid/s4u/Engine.hpp index 6a19ccd524..764bc089c6 100644 --- a/include/simgrid/s4u/Engine.hpp +++ b/include/simgrid/s4u/Engine.hpp @@ -63,7 +63,7 @@ public: template void register_actor(const std::string& name) { kernel::actor::ActorCodeFactory code_factory = [](std::vector args) { - return kernel::actor::ActorCode([args] { + return kernel::actor::ActorCode([args = std::move(args)]() mutable { F code(std::move(args)); code(); }); @@ -73,7 +73,7 @@ public: template void register_actor(const std::string& name, F code) { kernel::actor::ActorCodeFactory code_factory = [code](std::vector args) { - return kernel::actor::ActorCode([code, args] { code(std::move(args)); }); + return kernel::actor::ActorCode([code, args = std::move(args)]() mutable { code(std::move(args)); }); }; register_function(name, code_factory); } diff --git a/src/s4u/s4u_Engine.cpp b/src/s4u/s4u_Engine.cpp index 10502f9fb1..f7f8b717cb 100644 --- a/src/s4u/s4u_Engine.cpp +++ b/src/s4u/s4u_Engine.cpp @@ -115,7 +115,7 @@ void Engine::register_function(const std::string& name, const std::function)>& code) { - kernel::actor::ActorCodeFactory code_factory = [code](std::vector args) { + kernel::actor::ActorCodeFactory code_factory = [code{code}](std::vector args) mutable { return std::bind(std::move(code), std::move(args)); }; register_function(name, code_factory); -- 2.20.1