The ordering predicate to use to determine the minimum element.
The input range to search.
Complexity: O(range.length) Exactly range.length - 1 comparisons are needed.
The index of the first encounter of the minimum element in range. If the range is empty, -1 is returned.
Limitations: If at least one of the arguments is NaN, the result is an unspecified value. See std.algorithm.searching.maxElement for examples on how to cope with NaNs.
int[] a = [2, 3, 4, 1, 2, 4, 1, 1, 2]; // Minimum is 1 and first occurs in position 3 assert(a.minIndex == 3); // Get maximum index with minIndex assert(a.minIndex!"a > b" == 2); // Range is empty, so return value is -1 int[] b; assert(b.minIndex == -1); // Works with more custom types struct Dog { int age; } Dog[] dogs = [Dog(10), Dog(5), Dog(15)]; assert(dogs.minIndex!"a.age < b.age" == 1);
Computes the index of the first occurrence of range's minimum element.