How to make an infinite sequence in C++
boost, c++, c++11
Solution
The simpler thing, if you can depend on boost is to write something like this:
int i = 0;
auto gen = boost::make_generator_iterator([=]() mutable { return i++; });
C++14 version:
auto gen = boost::make_generator_iterator([i=0]() mutable { return i++;});
Documentation is here.
P.S.: I'm not sure if it will work without `result_type` member, which C++03 functor would need.
Problem
I'm using Visual Studio 2012 so C++11 is mostly OK... boost is also fine, but I would prefer to avoid other libreries, at least not widley used ones. I want to create a forward only iterator that returns an infinite sequence, in the most elegant way possible. For example a sequence of all the natural numbers. Basically I want the C++ equivilent of this f# code: ``` let nums = seq { while true do yield 1 yield 2 } ``` the above code basically creates an enumerator that returns [1;2;1;2...] I know I could do this by writing a class, but there's got to be a shorter way with all the new lambdas and all...