@@ -507,7 +507,7 @@ template assumeSortedContains(alias test = "a < b")
507
507
/+ +
508
508
Returns: the smallest index of a sorted array such
509
509
that the index corresponds to the arrays element at the index according to the predicate
510
- and array length if the array doesn't contain corresponding element.
510
+ and `-1` if the array doesn't contain corresponding element.
511
511
512
512
Params:
513
513
test = strict ordering symmetric predicate.
@@ -528,15 +528,15 @@ template assumeSortedEqualIndex(alias test = "a < b")
528
528
slice = sorted one-dimensional slice or array.
529
529
v = value to test with. It is passed to second argument.
530
530
+/
531
- size_t assumeSortedEqualIndex (Iterator, SliceKind kind, V)
531
+ sizediff_t assumeSortedEqualIndex (Iterator, SliceKind kind, V)
532
532
(auto ref Slice! (Iterator, 1 , kind) slice, auto ref scope const V v)
533
533
{
534
534
auto ti = transitionIndex! test(slice, v);
535
- return ti < slice.length && ! test(v, slice[ti]) ? ti : slice.length ;
535
+ return ti < slice.length && ! test(v, slice[ti]) ? ti : - 1 ;
536
536
}
537
537
538
538
// / ditto
539
- size_t assumeSortedEqualIndex (T, V)(scope T[] ar, auto ref scope const V v)
539
+ sizediff_t assumeSortedEqualIndex (T, V)(scope T[] ar, auto ref scope const V v)
540
540
{
541
541
return .assumeSortedEqualIndex! test(ar.sliced, v);
542
542
}
@@ -553,10 +553,10 @@ version(mir_test)
553
553
auto a = [0 , 1 , 2 , 3 , 4 , 6 ];
554
554
555
555
assert (a.assumeSortedEqualIndex(2 ) == 2 );
556
- assert (a.assumeSortedEqualIndex(5 ) == a.length );
556
+ assert (a.assumeSortedEqualIndex(5 ) == - 1 );
557
557
558
558
// <= non strict predicates doesn't work
559
- assert (a.assumeSortedEqualIndex! " a <= b" (2 ) == a.length );
559
+ assert (a.assumeSortedEqualIndex! " a <= b" (2 ) == - 1 );
560
560
}
561
561
562
562
/+ +
0 commit comments