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_ADJACENT_FIND_HPP
00008 #define INSTIGATE_STL_ADJACENT_FIND_HPP
00009
00059
00060 #include "concept.hpp"
00061 #include "_basis.hpp"
00062
00063
00064
00065
00066
00067
00068 namespace instigate {
00069 namespace stl {
00070 template <typename I, typename P>
00071 I adjacent_find(I b, I e, P p);
00072 template <typename I>
00073 I adjacent_find(I b, I e);
00074 }
00075 }
00076
00102 template <typename I>
00103 inline I instigate::stl::adjacent_find(I b, I e)
00104 {
00105 typedef typename instigate::stl::readable_iterator::interface<I>::
00106 value_type value_type;
00107 CHECK(instigate::stl::forward_iterator::requirements<I>);
00108 CHECK(instigate::stl::readable_iterator::requirements<I>);
00109 CHECK(instigate::generic::equality_comparable::
00110 requirements<value_type>);
00111 if (equal(b, e)) {
00112 return e;
00113 }
00114 char k[sizeof(I)];
00115 I* next = 0;
00116 assign(next, copy_constructor(k, b));
00117 assert(0 != next);
00118 increment(*next);
00119 while (!equal(*next, e)) {
00120 if (equal(const_dereference(b),const_dereference(*next))) {
00121 return b;
00122 }
00123 assign(b, *next);
00124 increment(*next);
00125 }
00126 return e;
00127 }
00155 template <typename I, typename P>
00156 inline I instigate::stl::adjacent_find(I b, I e, P p)
00157 {
00158 typedef typename instigate::stl::readable_iterator::interface<I>::
00159 value_type value_type;
00160 CHECK(instigate::stl::forward_iterator::requirements<I>);
00161 CHECK(instigate::stl::binary_predicate::requirements<P>);
00162 CHECK(instigate::stl::readable_iterator::requirements<I>);
00163 CHECK(instigate::generic::equality_comparable::
00164 requirements<value_type>);
00165 if (equal(b, e)) {
00166 return e;
00167 }
00168 char k[sizeof(I)];
00169 I* next = 0;
00170 assign(next, copy_constructor(k, b));
00171 assert(0 != next);
00172 increment(*next);
00173 while (!equal(*next, e)) {
00174 if (invoke_predicate(p, const_dereference(b),
00175 const_dereference(*next)))
00176 {
00177 return b;
00178 }
00179 assign(b, *next);
00180 increment(*next);
00181 }
00182 return e;
00183 }
00184
00185
00186
00187 #endif // INSTIGATE_STL_ADJACENT_FIND_HPP
00188