Penny Dreudter
Penny Dreudter

Reputation: 760

How to use std::move when dealing with universal refernce parameters being passed to a function/method

In the following code, which of the assignment to handler is correct or are they both equivalent to each other

#include <string>
#include <functional>

struct mything {
   using handler_t = std::function<void(const std::string&, double)>;

   void register_handler(handler_t&& handler) {
      /*option1:*/ handler_ = std::move(handler);
      /*option2:*/ handler_ = handler;
   }

   handler_t handler_;
};


int main() {
   mything mt;
   mt.register_handler([](const std::string&, double)->void {});
   return 0;
}

Upvotes: 6

Views: 55

Answers (0)

Related Questions