binSearch

Do binary search, pred(l) must be false, pred(r) must be true, and pred must have monotonic

[pred(l) = false, false, ..., false, true, true, ..., pred(r) = true]

  1. T binSearch(T l, T r)
    T
    binSearch
    (
    alias pred
    T
    )
    (
    T l
    ,
    T r
    )
    if (
    isIntegral!T
    )
  2. T binSearch(T l, T r, int cnt = 60)

Return Value

Type: T

minimum x, s.t. pred(x) = true

Examples

assert(binSearch!(x => x*x >= 100)(0, 20) == 10);
assert(binSearch!(x => x*x >= 101)(0, 20) == 11);
assert(binSearch!(x => true)(0, 20) == 1);
assert(binSearch!(x => false)(0, 20) == 20);

Meta