Error while generate DNA with uniform()
Salih Dincer
salihdb at hotmail.com
Sat Sep 3 22:03:24 UTC 2022
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 at 79
More information about the Digitalmars-d-learn
mailing list