On Mon, 14 May 2012 12:01:06 +0200, Peter Alexander
<peter.alexander...@gmail.com> wrote:
On Sunday, 13 May 2012 at 10:08:47 UTC, bearophile wrote:
Andrei Alexandrescu:
assumeSorted(range).contains(object)
is still one line, safer, and IMHO more self-explanatory.
It's self-explanatory if the name there contains something like
"binarySearch". Otherwise it is NOT self-explanatory, I can't
assume it will use a binary search.
So it's surely not intuitive.
Bye,
bearophile
100% agree with this.
How anyone can possibly think that using assumeSorted(r).contains(x) to
do a binary search is more self-explanatory than just writing
binarySearch(r, x) is beyond me. It's mind-boggling.
It is not intuitive, I agree. It is, however, documenting. You're not
calling binarySearch on any old array, you assume it is sorted, *then*
search it.
Perhaps it would be better to have a binarySearch function, which can
only take a SortedRange, and gives an explanatory error message when used
with a NonSortedRange.