00001
00002 #ifndef _INSTIGATE_STL_INTERNAL_HEADER_IN_ALGORITHM
00003 #error This is an internal header file used to implement Instigate STL.\
00004 It should never be included directly by a program.
00005 #endif
00006
00007 #ifndef INSTIGATE_STL_BINARY_SEARCH_HPP
00008 #define INSTIGATE_STL_BINARY_SEARCH_HPP
00009
00058
00059 #include "_basis.hpp"
00060 #include "concept.hpp"
00061 #include "_lower_bound.hpp"
00062
00063
00064
00065
00066
00067
00068 namespace instigate {
00069 namespace stl {
00070 template <typename F, typename L>
00071 bool binary_search(F b, F e, const L& v);
00072 template <typename F, typename L, typename C>
00073 bool binary_search(F b, F e, const L& v, C c);
00074 }
00075 }
00076
00077
00120 template <typename F, typename L>
00121 bool instigate::stl::binary_search(F b, F e, const L& v)
00122 {
00123 typedef typename instigate::stl::readable_iterator::interface<F>::
00124 value_type value_type;
00125 CHECK(instigate::stl::forward_iterator::requirements<F>);
00126 CHECK(instigate::stl::readable_iterator::requirements<F>);
00127 CHECK_SAME_TYPE(value_type, L);
00128 char k[sizeof(F)];
00129 F* i = 0;
00130 assign(i, copy_constructor(k, instigate::stl::lower_bound(b, e, v)));
00131 assert(0 != i);
00132 return (!equal(*i, e) && !less_than(v , const_dereference(*i)));
00133 }
00134
00177 template <typename F, typename L, typename C>
00178 bool instigate::stl::binary_search(F b, F e, const L& v, C c)
00179 {
00180 namespace FI = instigate::stl::forward_iterator;
00181 typedef typename instigate::stl::readable_iterator::interface<F>::
00182 value_type value_type;
00183 CHECK(instigate::stl::forward_iterator::requirements<F>);
00184 CHECK(instigate::stl::readable_iterator::requirements<F>);
00185 CHECK_SAME_TYPE(value_type, L);
00186 CHECK(instigate::stl::binary_predicate::requirements<C>);
00187 char k[sizeof(F)];
00188 F* i = 0;
00189 assign(i, copy_constructor(k, instigate::stl::lower_bound(b, e, v, c)));
00190 assert(0 != i);
00191 return (!equal(*i, e) &&
00192 !invoke_predicate(c, v, const_dereference(*i)));
00193 }
00194
00195
00196
00197 #endif // INSTIGATE_STL_BINARY_SEARCH_HPP
00198