Fix issue 22785: joiner should Unqual child ranges. (#8737)

* Fix issue 22785: `joiner` should `Unqual` child ranges.
This allows use with `immutable T[][]` and similar.

---------

Co-authored-by: Petar Kirov <petar.p.kirov@gmail.com>
This commit is contained in:
FeepingCreature 2023-04-20 00:59:19 +02:00 committed by GitHub
parent c26d25eecd
commit 656ae7905e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3632,18 +3632,18 @@ auto joiner(RoR, Separator)(RoR r, Separator sep)
/// Ditto
auto joiner(RoR)(RoR r)
if (isInputRange!RoR && isInputRange!(ElementType!RoR))
if (isInputRange!RoR && isInputRange!(Unqual!(ElementType!RoR)))
{
static struct Result
{
private:
RoR _items;
ElementType!RoR _current;
Unqual!(ElementType!RoR) _current;
enum isBidirectional = isForwardRange!RoR && isForwardRange!(ElementType!RoR) &&
isBidirectionalRange!RoR && isBidirectionalRange!(ElementType!RoR);
static if (isBidirectional)
{
ElementType!RoR _currentBack;
Unqual!(ElementType!RoR) _currentBack;
bool reachedFinalElement;
}
@ -4293,6 +4293,28 @@ if (isInputRange!RoR && isInputRange!(ElementType!RoR))
assert([only(S(null))].joiner.front == S(null));
}
// https://issues.dlang.org/show_bug.cgi?id=22785
@safe unittest
{
import std.algorithm.iteration : joiner, map;
import std.array : array;
static immutable struct S
{
int value;
}
static immutable struct T
{
S[] arr;
}
auto range = [T([S(3)]), T([S(4), S(5)])];
assert(range.map!"a.arr".joiner.array == [S(3), S(4), S(5)]);
}
/++
Implements the homonym function (also known as `accumulate`, $(D
compress), `inject`, or `foldl`) present in various programming