Skip to content

Instantly share code, notes, and snippets.

@gmichokostas
Last active November 26, 2017 11:43
Show Gist options
  • Save gmichokostas/a9d1c644e8272cda1914a28bc012929f to your computer and use it in GitHub Desktop.
Save gmichokostas/a9d1c644e8272cda1914a28bc012929f to your computer and use it in GitHub Desktop.
#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