https://issues.dlang.org/show_bug.cgi?id=23319
--- Comment #2 from Ali Cehreli <acehr...@yahoo.com> --- Thank you for an alternative but it has the same limitation, right? gen!(() => const(int)(42)); deneme.d(4431): Error: cannot modify `const` expression `this.func` deneme.d(4448): Error: template instance `deneme.gen!(function () pure nothrow @nogc @safe => 42)` error instantiating Line 4431 is this one: void popFront() { func = fn(); } Please note that this bug report is about std.range.Generator. No hand-written code can magically fix it. --