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_TRANSFORM_HPP
00008 #define INSTIGATE_STL_TRANSFORM_HPP
00009
00058
00059 #include "concept.hpp"
00060
00061
00062
00063
00064
00065
00066 namespace instigate {
00067 namespace stl {
00068 template <typename I, typename O, typename U>
00069 inline O transform(I b, I e, O r, U f);
00070 template <typename I, typename I2, typename O, typename B>
00071 inline O transform(I b, I e, I2 b2, O r, B f);
00072 }
00073 }
00074
00113 template <typename I, typename O, typename U>
00114 inline O instigate::stl::transform(I b, I e, O r, U f)
00115 {
00116 namespace SP = instigate::stl::single_pass_iterator;
00117 namespace RI = instigate::stl::readable_iterator;
00118 namespace INC = instigate::stl::incrementable_iterator;
00119 namespace WR = instigate::stl::writable_iterator;
00120 namespace UF = instigate::stl::unary_function;
00121 CHECK(SP::requirements<I>);
00122 CHECK(RI::requirements<I>);
00123 CHECK(INC::requirements<O>);
00124 CHECK(WR::requirements<O>);
00125 CHECK(UF::requirements<U>);
00126 CHECK_CONVERTIBILITY(typename RI::interface<I>::value_type,
00127 typename UF::interface<U>::argument_type);
00128 CHECK_CONVERTIBILITY(typename WR::interface<O>::value_type,
00129 typename UF::interface<U>::result_type);
00130 for (; !equal(b, e); increment(b), increment(r)){
00131 dereference_assign(r, invoke(f, const_dereference(b)));
00132 }
00133 return r;
00134 }
00135
00175 template <typename I, typename I2, typename O, typename B>
00176 inline O instigate::stl::transform(I b, I e, I2 b2, O r, B f)
00177 {
00178 namespace SP = instigate::stl::single_pass_iterator;
00179 namespace RI = instigate::stl::readable_iterator;
00180 namespace INC = instigate::stl::incrementable_iterator;
00181 namespace WR = instigate::stl::writable_iterator;
00182 namespace BF = instigate::stl::binary_function;
00183 CHECK(SP::requirements<I>);
00184 CHECK(RI::requirements<I>);
00185 CHECK(SP::requirements<I2>);
00186 CHECK(RI::requirements<I2>);
00187 CHECK(INC::requirements<O>);
00188 CHECK(WR::requirements<O>);
00189 CHECK(BF::requirements<B>);
00190 CHECK_CONVERTIBILITY(typename RI::interface<I>::value_type,
00191 typename BF::interface<B>::first_argument_type);
00192 CHECK_CONVERTIBILITY(typename RI::interface<I2>::value_type,
00193 typename BF::interface<B>::second_argument_type);
00194 CHECK_CONVERTIBILITY(typename BF::interface<B>::result_type,
00195 typename WR::interface<I2>::value_type);
00196 for (; !equal(b, e); increment(b), increment(b2), increment(r) ){
00197 dereference_assign(r, invoke(f, const_dereference(b),
00198 const_dereference(b2)));
00199 }
00200 return r;
00201 }
00202
00203
00204
00205 #endif // INSTIGATE_STL_TRANSFORM_HPP