On Saturday, 3 September 2022 at 21:09:09 UTC, Ali Çehreli wrote:
Salih had asked:

>> Can we solve this issue with our own `generate()` structure?

Yes, I did the following to determine that adding Unqual was a solution:

- Copy generate() functions to your source file,

- Copy the Generator struct to your source file,

- Edit the definition of Generator's elem_ member as I hinted in the bug.

But the bug may be in the templates, not in the structure. Maybe `
template functionTypeOf(alias func)`

For example:

```d
auto gen(alias fun)() {
    auto gen = Gen!fun();
    gen.popFront();
    return gen;
}

struct Gen(alias fn)
{
  import std.traits:
  ReturnType!fn func;

  enum empty = false;
  auto front() { return func; }
  void popFront() { func = fn(); }
}

unittest
{
  import std.random : uniform;
  import std.range : takeExactly;

  enum E {
    O = '0', P, Q, R, S, T, U, V, W, X,
    A = 'A', B, C, D, E, F
  }
  auto range = gen!(function char()  =>
                   uniform!"[]"(E.min, E.max))
                   .takeExactly(15);
  assert(range.to!long(15) < long.max);
}
```
SDB@79

Reply via email to