Fix Issue 23319 - std.range.Generator does not work with non-mutable elements

This commit is contained in:
RazvanN7 2022-12-05 14:42:26 +02:00 committed by The Dlang Bot
parent 09275da681
commit 67155f04e7

View file

@ -3774,10 +3774,17 @@ private:
alias fun = Fun[0];
enum returnByRef_ = (functionAttributes!fun & FunctionAttribute.ref_) ? true : false;
static if (returnByRef_)
ReturnType!fun *elem_;
import std.traits : hasIndirections;
static if (!hasIndirections!(ReturnType!fun))
alias RetType = Unqual!(ReturnType!fun);
else
ReturnType!fun elem_;
alias RetType = ReturnType!fun;
static if (returnByRef_)
RetType *elem_;
else
RetType elem_;
public:
/// Range primitives
enum empty = false;
@ -3866,6 +3873,13 @@ public:
assert(g.front == f + 5);
}
// https://issues.dlang.org/show_bug.cgi?id=23319
@safe pure nothrow unittest
{
auto b = generate!(() => const(int)(42));
assert(b.front == 42);
}
/**
Repeats the given forward range ad infinitum. If the original range is
infinite (fact that would make `Cycle` the identity application),