What is the fastest and shortest way to pass a function as parameter of another function without using other libraries other than the std one in just one line?
I mea
C++11 provides anonymous functions:
forloop(3, []{ std::cout "Hi!"; });
Example:
#include #include void forloop(int times, std::function f) { for(int i = 0; i < times; i++) { f(); } } int main() { forloop(3, [] () { std::cout << "Hello world"; }); }