mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 22:21:09 +03:00
Fix Issue 18806 - InputRange for std.algorithm.minIndex
This commit is contained in:
parent
8356511ffb
commit
5795db7ab7
1 changed files with 36 additions and 2 deletions
|
@ -3789,7 +3789,7 @@ irreflexive (`pred(a, a)` is `false`).
|
|||
Params:
|
||||
pred = The ordering predicate to use to determine the extremum (minimum or
|
||||
maximum) element.
|
||||
range = The $(REF_ALTTEXT input range, isInputRange, std,range,primitives) to search.
|
||||
range = The $(REF_ALTTEXT forward range, isForwardRange, std,range,primitives) to search.
|
||||
|
||||
Returns: The position of the minimum (respectively maximum) element of forward
|
||||
range `range`, i.e. a subrange of `range` starting at the position of its
|
||||
|
@ -3909,7 +3909,7 @@ See_Also:
|
|||
$(LREF maxIndex), $(REF min, std,algorithm,comparison), $(LREF minCount), $(LREF minElement), $(LREF minPos)
|
||||
*/
|
||||
sizediff_t minIndex(alias pred = "a < b", Range)(Range range)
|
||||
if (isForwardRange!Range && !isInfinite!Range &&
|
||||
if (isInputRange!Range && !isInfinite!Range &&
|
||||
is(typeof(binaryFun!pred(range.front, range.front))))
|
||||
{
|
||||
if (range.empty) return -1;
|
||||
|
@ -4009,6 +4009,40 @@ if (isForwardRange!Range && !isInfinite!Range &&
|
|||
assert(arr2d.minIndex!"a[1] < b[1]" == 2);
|
||||
}
|
||||
|
||||
@safe nothrow pure unittest
|
||||
{
|
||||
// InputRange test
|
||||
|
||||
static struct InRange
|
||||
{
|
||||
@property int front()
|
||||
{
|
||||
return arr[index];
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return arr.length == index;
|
||||
}
|
||||
|
||||
void popFront()
|
||||
{
|
||||
index++;
|
||||
}
|
||||
|
||||
int[] arr;
|
||||
size_t index = 0;
|
||||
}
|
||||
|
||||
static assert(isInputRange!InRange);
|
||||
|
||||
auto arr1 = InRange([5, 2, 3, 4, 5, 3, 6]);
|
||||
auto arr2 = InRange([7, 3, 8, 2, 1, 4]);
|
||||
|
||||
assert(arr1.minIndex == 1);
|
||||
assert(arr2.minIndex == 4);
|
||||
}
|
||||
|
||||
/**
|
||||
Computes the index of the first occurrence of `range`'s maximum element.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue