diff --git a/std/range/package.d b/std/range/package.d index b8f30ce7c..888ac1a5d 100644 --- a/std/range/package.d +++ b/std/range/package.d @@ -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),