// Casting Out Nines Generator - Compiles with gcc4.6, MSVC 11, and CLang3 // // Nigel Galloway. June 24th., 2012 // #include #include struct ran { const int base; std::vector rs; ran(const int base) : base(base) { for (int nz=0; nzbase) ,_next((_ran->base-1)*_x + _ran->rs[_r]) { while (operator*() < start) operator++(); } const co9& operator++() { const int oldr = _r; _r = ++_r%_ran->rs.size(); if (_rbase-1)*_x + _ran->rs[_r]; return *this; } }; int main() { ran r(10); for (int i : co9(1,99,&r)) { std::cout << i << ' '; } return 0; }