How do each of the following behave differently? I'm unclear what effect const
has on the function parameter, and what the difference in this case would be between passing by value, by reference, or by rvalue reference. Which one of these is "best"?
#include <functional>
void foo_with_func( std::function<void()> f) { ...; f(); ...; }
void foo_with_func( std::function<void()>& f) { ...; f(); ...; }
void foo_with_func( std::function<void()>&& f) { ...; f(); ...; }
void foo_with_func(const std::function<void()> f) { ...; f(); ...; }
void foo_with_func(const std::function<void()>& f) { ...; f(); ...; }
void foo_with_func(const std::function<void()>&& f) { ...; f(); ...; }
Aucun commentaire:
Enregistrer un commentaire