summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-07-04 13:34:19 +0200
committerPatrick Simianer <p@simianer.de>2014-07-04 13:34:19 +0200
commitb822f350e3936c2aa16ca73355afee28e6b4454c (patch)
treeb6f931b6835877d64f4f57bc086990a83d54db62
parentcd25485777d9525bd4b29ab350f1ff9e864cf015 (diff)
generator.cc
-rw-r--r--c,cc/generator.cc15
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;
+}