Last active
November 26, 2017 11:43
-
-
Save gmichokostas/a9d1c644e8272cda1914a28bc012929f 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 <iostream> | |
using namespace std; | |
auto upto(int& beg, int& end) -> decltype(std::function<int()>()) { | |
return [&]() { | |
if (beg <= end) { | |
return beg++; | |
} | |
return 0; | |
}; | |
} | |
int main(void) { | |
int i = 0; | |
int j = 3; | |
auto it = upto(i, j); | |
cout << it() << endl; // 0 | |
cout << it() << endl; // 1 | |
cout << it() << endl; // 2 | |
cout << it() << endl; // 3 | |
cout << it() << endl; // 0 | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment