1 #ifndef STDXfg_ALGORITHMX_H
2 #define STDXfg_ALGORITHMX_H
3
4 // Some std:: namespace enhancements
5
6 #include <algorithm>
7
8 namespace stdx_fg {
9
10 template <class ForwardIterator, class T, class Compare>
lower_bound(ForwardIterator first,ForwardIterator last,const T & val,Compare comp)11 ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, const T& val, Compare comp)
12 {
13 ForwardIterator it;
14 typename std::iterator_traits<ForwardIterator>::difference_type count, step;
15 count = std::distance(first,last);
16 while(count > 0)
17 {
18 it = first;
19 step = count/2;
20 std::advance (it,step);
21 if (comp(*it, val))
22 {
23 first= ++it;
24 count -= step+1;
25 }
26 else
27 count = step;
28 }
29 return first;
30 }
31
32 } // end namespace stdx_fg
33
34 #endif
35