Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<class _FwdIt,
- class _Ty,
- class _Diff> inline
- _FwdIt _Lower_bound(_FwdIt _First, _FwdIt _Last, const _Ty& _Val, _Diff *)
- { // find first element not before _Val, using operator<
- _Diff _Count = 0;
- _Distance(_First, _Last, _Count);
- while (0 < _Count)
- { // divide and conquer, find half that contains answer
- _Diff _Count2 = _Count / 2;
- _FwdIt _Mid = _First;
- _STD advance(_Mid, _Count2);
- if (*_Mid < _Val)
- // if (_DEBUG_LT(*_Mid, _Val))
- { // try top half
- _First = ++_Mid;
- _Count -= _Count2 + 1;
- }
- else
- _Count = _Count2;
- }
- return (_First);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement