diff options
-rw-r--r-- | c,cc/generator.cc | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/c,cc/generator.cc b/c,cc/generator.cc new file mode 100644 index 0000000..c073e2e --- /dev/null +++ b/c,cc/generator.cc @@ -0,0 +1,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; +} |