Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Variables captured by copy are constant and cannot be std::move'd.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 19 Nov 2020 08:35:48 +0000 (09:35 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 19 Nov 2020 10:41:07 +0000 (11:41 +0100)
Try to fix with C++14 generalized lambda capture and 'mutable' specifier.

include/simgrid/s4u/Engine.hpp
src/s4u/s4u_Engine.cpp

index 6a19ccd..764bc08 100644 (file)
@@ -63,7 +63,7 @@ public:
   template <class F> void register_actor(const std::string& name)
   {
     kernel::actor::ActorCodeFactory code_factory = [](std::vector<std::string> 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 <class F> void register_actor(const std::string& name, F code)
   {
     kernel::actor::ActorCodeFactory code_factory = [code](std::vector<std::string> 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);
   }
index 10502f9..f7f8b71 100644 (file)
@@ -115,7 +115,7 @@ void Engine::register_function(const std::string& name, const std::function<void
 /** Registers the main function of an actor that will be launched from the deployment file */
 void Engine::register_function(const std::string& name, const std::function<void(std::vector<std::string>)>& code)
 {
-  kernel::actor::ActorCodeFactory code_factory = [code](std::vector<std::string> args) {
+  kernel::actor::ActorCodeFactory code_factory = [code{code}](std::vector<std::string> args) mutable {
     return std::bind(std::move(code), std::move(args));
   };
   register_function(name, code_factory);