FC++ 遅延リスト
enum_from を使用して無限リストを作成する
引数は連番の開始値
#include <iostream> #include <iterator> #include <algorithm> #include <boost/fcpp/prelude.hpp> using namespace std; using namespace boost::fcpp; int main() { list<int> ls = enum_from(1); // 1, 2, 3...の無限リストを作成 copy(ls.begin(), ls.end(), ostream_iterator<int>(cout, ",")); // 1,2,3,4,5,6,........................ひどい目にあった! return 0; }
無限リストは遅延評価されるリストなので必要になったときに必要な分だけ計算される