Skip to content

Instantly share code, notes, and snippets.

@ButchDean
Last active August 29, 2015 14:19
Show Gist options
  • Save ButchDean/91977155431ef2f46b77 to your computer and use it in GitHub Desktop.
Save ButchDean/91977155431ef2f46b77 to your computer and use it in GitHub Desktop.
C++11 lambda-based function execution example. Awesome for test harness.
#include <cstdio>
#include <vector>
#include <algorithm>
typedef void (*func)();
void Func1()
{
std::puts("Func1() called.");
}
void Func2()
{
std::puts("Func2() called.");
}
int main()
{
std::vector<func> funcs = {Func1, Func2};
auto funcRun = [] (func f) { (*f)(); };
for_each(funcs.begin(), funcs.end(), funcRun);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment