I do not quite understand what instances of std::function
actually contain.
Is it more efficient to pass them by-value or by-reference?
What are the performance effects in the following examples?
by-value:
void printStats(std::function<void(const char *)> printer);
. . .
std::string tmp;
printStats([&tmp](const char * msg){ tmp += msg; });
by rvalue-reference:
void printStats(std::function<void(const char *)>&& printer);
. . .
std::string tmp;
printStats([&tmp](const char * msg){ tmp += msg; });
Aucun commentaire:
Enregistrer un commentaire