Last active
August 29, 2015 14:19
-
-
Save ButchDean/91977155431ef2f46b77 to your computer and use it in GitHub Desktop.
C++11 lambda-based function execution example. Awesome for test harness.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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