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_FIND_FIRST_OF_HPP
00008 #define INSTIGATE_STL_FIND_FIRST_OF_HPP
00009
00010
00060
00061 #include "concept.hpp"
00062 #include "_basis.hpp"
00063
00064
00065
00066
00067
00068
00069 namespace instigate {
00070 namespace stl {
00071 template <typename I, typename F>
00072 I find_first_of(I b, I e, F f, F l);
00073 template <typename I, typename F, typename BP>
00074 I find_first_of(I b, I e, F f, F l, BP p);
00075 }
00076 }
00077
00120 template <typename I, typename F>
00121 I instigate::stl::find_first_of(I b, I e, F f, F l)
00122 {
00123 namespace SP = instigate::stl::single_pass_iterator;
00124 namespace RI = instigate::stl::readable_iterator;
00125 namespace FI = instigate::stl::forward_iterator;
00126 namespace EQ = instigate::generic::equality_comparable;
00127 CHECK(RI::requirements<I>);
00128 CHECK(SP::requirements<I>);
00129 CHECK(FI::requirements<F>);
00130 CHECK(RI::requirements<F>);
00131 CHECK(EQ::requirements<typename RI::interface<I>::value_type>);
00132 char p[sizeof(F)];
00133 while (!equal(b, e)) {
00134 F* i = 0;
00135 assign(i, copy_constructor(p, f));
00136 assert(0 != i);
00137 while (!equal((*i), l)) {
00138 if (equal(const_dereference(b), const_dereference(*i)))
00139 {
00140 return b;
00141 }
00142 increment(*i);
00143 }
00144 increment(b);
00145 }
00146 return e;
00147 }
00148
00197 template <typename I, typename F, typename BP>
00198 I instigate::stl::find_first_of(I b, I e, F f, F l, BP p)
00199 {
00200 namespace SP = instigate::stl::single_pass_iterator;
00201 namespace RI = instigate::stl::readable_iterator;
00202 namespace FI = instigate::stl::forward_iterator;
00203 namespace EQ = instigate::generic::equality_comparable;
00204 namespace BPI = instigate::stl::binary_predicate;
00205 CHECK(RI::requirements<I>);
00206 CHECK(SP::requirements<I>);
00207 CHECK(FI::requirements<F>);
00208 CHECK(RI::requirements<F>);
00209 CHECK(BPI::requirements<BP>);
00210 typedef typename RI::interface<I>::value_type value_type1;
00211 typedef typename RI::interface<F>::value_type value_type2;
00212 typedef typename BPI::interface<BP>::
00213 first_argument_type first_argument_type;
00214 typedef typename BPI::interface<BP>::
00215 second_argument_type second_argument_type;
00216 CHECK_CONVERTIBILITY(value_type1, first_argument_type);
00217 CHECK_CONVERTIBILITY(value_type2, second_argument_type);
00218 char t[sizeof(F)];
00219 while (!equal(b, e)) {
00220 F* i = 0;
00221 assign(i, copy_constructor(t, f));
00222 assert(0 != i);
00223 while (!equal((*i), l)) {
00224 if (invoke_predicate(p, const_dereference(b),
00225 const_dereference(*i)))
00226 {
00227 return b;
00228 }
00229 increment(*i);
00230 }
00231 increment(b);
00232 }
00233 return e;
00234 }
00235
00236
00237
00238 #endif // INSTIGATE_STL_FIND_FIRST_OF_HPP