mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 06:30:28 +03:00
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:
parent
c26d25eecd
commit
656ae7905e
1 changed files with 25 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue