php - Can't Understand 1 Line of Code in C++ STL Source: Lower_Bound/Upper_Bound -
i writing code find last key value no more given integer php. e.g.,array(0=>1,1=>2,2=>3,3=>3,4=>4). given integer 3, find key 3.(binary search) and looked references binary search on internet. find this, find first key value no less given integer c++. says: template <class _forwarditer, class _tp, class _distance> _forwarditer __lower_bound(_forwarditer __first, _forwarditer __last, const _tp& __val, _distance*) { _distance __len = 0; distance(__first, __last, __len); _distance __half; _forwarditer __middle; while (__len > 0) { __half = __len >> 1; __middle = __first; advance(__middle, __half); if (*__middle < __val) { __first = __middle; ++__first; __len = __len - __half - 1; } else __len = __half; // <======this line } return __first; } well, why using "__len = __half;" rather "__len = __half + 1;"? won't ...