Created
August 2, 2017 15:27
-
-
Save cblp/26402491a83b2cc84a2ec0e77b058a42 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <functional> | |
#include <iostream> | |
using namespace std; | |
void cond(bool condition, function<void()> ifTrue, function<void()> ifFalse) { | |
function<void()> branches[] = {ifFalse, ifTrue}; | |
branches[condition](); | |
} | |
template <typename T> | |
void enumerateDo(T start, T step, T stop, void action(int)) { | |
cond( | |
start <= stop, | |
[=]{ | |
action(start); | |
enumerateDo(start + step, step, stop, action); | |
}, | |
[]{} | |
); | |
} | |
int main() { | |
enumerateDo(3, 2, 10, [](int x){cout << x << ' ';}); | |
cout << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment