From b822f350e3936c2aa16ca73355afee28e6b4454c Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Fri, 4 Jul 2014 13:34:19 +0200 Subject: generator.cc --- c,cc/generator.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 c,cc/generator.cc 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 +#include + + +std::function 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; +} -- cgit v1.2.3