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.
1 int[] a = [2, 3, 4, 1, 2, 4, 1, 1, 2]; 2 3 // Minimum is 1 and first occurs in position 3 4 assert(a.minIndex == 3); 5 // Get maximum index with minIndex 6 assert(a.minIndex!"a > b" == 2); 7 8 // Range is empty, so return value is -1 9 int[] b; 10 assert(b.minIndex == -1); 11 12 // Works with more custom types 13 struct Dog { int age; } 14 Dog[] dogs = [Dog(10), Dog(5), Dog(15)]; 15 assert(dogs.minIndex!"a.age < b.age" == 1);
Computes the index of the first occurrence of range's minimum element.