mirror of
https://github.com/dlang/phobos.git
synced 2025-05-02 16:10:45 +03:00
Issue 10408 - Fix compile error with multiple-function reduce on a const range.
This commit is contained in:
parent
fdbf4f32c1
commit
58d403a02d
1 changed files with 13 additions and 2 deletions
|
@ -743,11 +743,12 @@ template reduce(fun...) if (fun.length >= 1)
|
|||
else
|
||||
{
|
||||
static assert(fun.length > 1);
|
||||
typeof(adjoin!(staticMap!(binaryFun, fun))(r.front, r.front))
|
||||
Unqual!(typeof(r.front)) seed = r.front;
|
||||
typeof(adjoin!(staticMap!(binaryFun, fun))(seed, seed))
|
||||
result = void;
|
||||
foreach (i, T; result.Types)
|
||||
{
|
||||
emplace(&result[i], r.front);
|
||||
emplace(&result[i], seed);
|
||||
}
|
||||
r.popFront();
|
||||
return reduce(result, r);
|
||||
|
@ -905,6 +906,16 @@ unittest
|
|||
r = reduce!"a + b"(a, c);
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
// Issue #10408 - Two-function reduce of a const array.
|
||||
const numbers = [10, 30, 20];
|
||||
immutable m = reduce!(min)(numbers);
|
||||
assert(m == 10);
|
||||
immutable minmax = reduce!(min, max)(numbers);
|
||||
assert(minmax == tuple(10, 30));
|
||||
}
|
||||
|
||||
/**
|
||||
Fills $(D range) with a $(D filler).
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue