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_PARTIAL_SUM_HPP
00008 #define INSTIGATE_STL_PARTIAL_SUM_HPP
00009
00059
00060 #include "_basis.hpp"
00061 #include "concept.hpp"
00062
00063
00064
00065
00066
00067
00068 namespace instigate {
00069 namespace stl {
00070 namespace implementation {
00071 template <typename I, typename O, typename T>
00072 O partial_sum_aux(I b, I e, O r, T*);
00073 template <typename I, typename O, typename T, typename F>
00074 O partial_sum_aux(I b, I e, O r, T*, F f);
00075 }
00076 template <typename I, typename O>
00077 O partial_sum(I b, I e, O r);
00078 template <typename I, typename O, typename F>
00079 O partial_sum(I b, I e, O r, F f);
00080 }
00081 }
00082
00120 template <typename I, typename O>
00121 O instigate::stl::partial_sum(I b, I e, O r)
00122 {
00123 typedef typename instigate::stl::readable_iterator::interface<I>::
00124 value_type value_type_in;
00125 typedef typename instigate::stl::writable_iterator::interface<O>::
00126 value_type value_type_out;
00127 CHECK(instigate::stl::single_pass_iterator::requirements<I>);
00128 CHECK(instigate::stl::incrementable_iterator::requirements<O>);
00129 CHECK(instigate::stl::readable_iterator::requirements<I>);
00130 CHECK(instigate::stl::writable_iterator::requirements<O>);
00131 CHECK_CONVERTIBILITY(value_type_in , value_type_out);
00132 if (equal(b, e)) {
00133 return r;
00134 }
00135 dereference_assign(r, const_dereference(b));
00136 value_type_in* k = 0;
00137 return instigate::stl::implementation::partial_sum_aux(b, e, r, k);
00138 }
00139
00141 template <typename I, typename O, typename T>
00142 O instigate::stl::implementation::partial_sum_aux(I b, I e, O r, T*)
00143 {
00144 T value = const_dereference(b);
00145 increment(b);
00146 while (!equal(b, e)) {
00147 assign(value, value + const_dereference(b));
00148 increment(r);
00149 dereference_assign(r, value);
00150 increment(b);
00151 }
00152 increment(r);
00153 return r;
00154 }
00155
00201 template <typename I, typename O, typename F>
00202 O instigate::stl::partial_sum(I b, I e, O r, F f)
00203 {
00204 typedef typename instigate::stl::readable_iterator::interface<I>::
00205 value_type value_type_in;
00206 typedef typename instigate::stl::writable_iterator::interface<I>::
00207 value_type value_type_out;
00208 CHECK(instigate::stl::single_pass_iterator::requirements<I>);
00209 CHECK(instigate::stl::incrementable_iterator::requirements<O>);
00210 CHECK(instigate::stl::readable_iterator::requirements<I>);
00211 CHECK(instigate::stl::writable_iterator::requirements<O>);
00212 CHECK(instigate::stl::binary_function::requirements<F>);
00213 CHECK_CONVERTIBILITY(value_type_in , value_type_out);
00214 if (equal(b, e)) {
00215 return r;
00216 }
00217 dereference_assign(r, const_dereference(b));
00218 value_type_in* k = 0;
00219 return instigate::stl::implementation::partial_sum_aux(b, e, r, k, f);
00220 }
00221
00223 template <typename I, typename O, typename T, typename F>
00224 O instigate::stl::implementation::partial_sum_aux(I b, I e, O r, T*, F f)
00225 {
00226 T value = const_dereference(b);
00227 increment(b);
00228 while (!equal(b, e)) {
00229 value = invoke(f, value, const_dereference(b));
00230 increment(r);
00231 dereference_assign(r, value);
00232 increment(b);
00233 }
00234 increment(r);
00235 return r;
00236 }
00237
00238
00239
00240 #endif // INSTIGATE_STL_PARTIAL_SUM_HPP
00241