summaryrefslogtreecommitdiff
path: root/c,cc/generator.cc
blob: c073e2ed016ea18fb537a6b0bc2fa518cbab0b89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <functional>
#include <iostream>


std::function<int()> generator = []{
    int i = 0;
      return [=]() mutable {
        return i < 10 ? i++ : -1;
      };
}();

int main(void)
{
int ret = 0; while ((ret = generator()) != -1) std::cout << "generator: " << ret << std::endl;
}