[Issue 23319] std.range.Generator does not work with non-mutable elements
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Dec 5 01:25:33 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23319
Salih Dincer <salihdb at hotmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |salihdb at hotmail.com
--- Comment #1 from Salih Dincer <salihdb at hotmail.com> ---
This can be an alternative:
template gen (alias fn) {
struct GenRes { //
import std.traits;
ReturnType!fn func;
enum empty = false;
auto front() { return func; }
void popFront() { func = fn(); }
}
GenRes gen() {
auto gen = GenRes();
gen.popFront();
return gen;
}
} unittest {
import std.range, std.random : uniform;
import std.stdio;
enum E : char { False = 48, True }
auto r = gen!(function char() => uniform!E);
r.take(12).writefln!"[%s]";
}
Sources:
https://forum.dlang.org/post/tf0j3c$246r$1@digitalmars.com
https://forum.dlang.org/post/dvtuclqeijpsukxidhlg@forum.dlang.org
--
More information about the Digitalmars-d-bugs
mailing list