mirror of
https://github.com/dlang/phobos.git
synced 2025-04-30 15:10:46 +03:00
Fix issue 23993: Discard Rebindable before passing extremum to comparator.
This commit is contained in:
parent
f22cc260f8
commit
f715941036
1 changed files with 21 additions and 3 deletions
|
@ -1349,13 +1349,23 @@ if (isInputRange!Range && !isInfinite!Range &&
|
||||||
// if we only have one statement in the loop, it can be optimized a lot better
|
// if we only have one statement in the loop, it can be optimized a lot better
|
||||||
static if (__traits(isSame, map, a => a))
|
static if (__traits(isSame, map, a => a))
|
||||||
{
|
{
|
||||||
|
CommonElement getExtremeElement()
|
||||||
|
{
|
||||||
|
static if (is(typeof(extremeElement) == T[], T))
|
||||||
|
{
|
||||||
|
return extremeElement;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return extremeElement.get;
|
||||||
|
}
|
||||||
|
}
|
||||||
// direct access via a random access range is faster
|
// direct access via a random access range is faster
|
||||||
static if (isRandomAccessRange!Range)
|
static if (isRandomAccessRange!Range)
|
||||||
{
|
{
|
||||||
foreach (const i; 0 .. r.length)
|
foreach (const i; 0 .. r.length)
|
||||||
{
|
{
|
||||||
if (selectorFun(r[i], extremeElement))
|
if (selectorFun(r[i], getExtremeElement))
|
||||||
{
|
{
|
||||||
extremeElement = r[i];
|
extremeElement = r[i];
|
||||||
}
|
}
|
||||||
|
@ -1365,7 +1375,7 @@ if (isInputRange!Range && !isInfinite!Range &&
|
||||||
{
|
{
|
||||||
while (!r.empty)
|
while (!r.empty)
|
||||||
{
|
{
|
||||||
if (selectorFun(r.front, extremeElement))
|
if (selectorFun(r.front, getExtremeElement))
|
||||||
{
|
{
|
||||||
extremeElement = r.front;
|
extremeElement = r.front;
|
||||||
}
|
}
|
||||||
|
@ -3880,6 +3890,14 @@ if (isInputRange!Range && !isInfinite!Range &&
|
||||||
assert(arr.maxElement!"a.val".val == 1);
|
assert(arr.maxElement!"a.val".val == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://issues.dlang.org/show_bug.cgi?id=23993
|
||||||
|
@safe unittest
|
||||||
|
{
|
||||||
|
import std.bigint : BigInt;
|
||||||
|
|
||||||
|
assert([BigInt(2), BigInt(3)].maxElement == BigInt(3));
|
||||||
|
}
|
||||||
|
|
||||||
// minPos
|
// minPos
|
||||||
/**
|
/**
|
||||||
Computes a subrange of `range` starting at the first occurrence of `range`'s
|
Computes a subrange of `range` starting at the first occurrence of `range`'s
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue