www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23319] New: std.range.Generator does not work with

https://issues.dlang.org/show_bug.cgi?id=23319

          Issue ID: 23319
           Summary: std.range.Generator does not work with non-mutable
                    elements
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: acehreli yahoo.com

The following code is expected to work at least with types having no
indirections e.g. the value of an enum.

And it should work for immutable as well.

import std.range : generate;
void main() {
  generate!(() => const(int)(42));
}

/usr/include/dlang/dmd/std/range/package.d(3808): Error: cannot modify `const`
expression `this.elem_`
/usr/include/dlang/dmd/std/range/package.d(3767): Error: template instance
`std.range.primitives.isInputRange!(Generator!(function () pure nothrow  nogc
 safe => 42))` error instantiating
/usr/include/dlang/dmd/std/range/package.d(3767):        while evaluating:
`static assert(isInputRange!(Generator!(function () pure nothrow  nogc  safe =>
42)))`
/usr/include/dlang/dmd/std/range/package.d(3723): Error: template instance
`std.range.Generator!(function () pure nothrow  nogc  safe => 42)` error
instantiating


A fix would be to use Unqual inside std.range.Generator (but of course guarding
with std.traits.hasIndirections first):

      Unqual!(ReturnType!fun) elem_;

--
Sep 02 2022