1 const int[9] x = [1, 3, 5, 6, 8, 9, 10, 13, 15]; 2 assert(x.binarySearch(0) == size_t.max); 3 assert(x.binarySearch(1) == 0); 4 assert(x.binarySearch(2) == size_t.max); 5 assert(x.binarySearch(3) == 1); 6 assert(x.binarySearch(4) == size_t.max); 7 assert(x.binarySearch(5) == 2); 8 assert(x.binarySearch(6) == 3); 9 assert(x.binarySearch(7) == size_t.max); 10 assert(x.binarySearch(8) == 4); 11 assert(x.binarySearch(9) == 5); 12 assert(x.binarySearch(10) == 6); 13 assert(x.binarySearch(11) == size_t.max); 14 assert(x.binarySearch(12) == size_t.max); 15 assert(x.binarySearch(13) == 7); 16 assert(x.binarySearch(14) == size_t.max); 17 assert(x.binarySearch(15) == 8);
This function returns the index of the value if it exist among values, size_t.max otherwise.
TODO Should we extend to isRandomAccessRange support? In that case we don't get static array support by default.