00001 #ifndef _INSTIGATE_STL_INTERNAL_HEADER_IN_ALGORITHM
00002 #error This is an internal header file used to implement Instigate STL.\
00003 It should never be included directly by a program.
00004 #endif
00005
00006 #ifndef INSTIGATE_STL_INNER_PRODUCT_HPP
00007 #define INSTIGATE_STL_INNER_PRODUCT_HPP
00008
00058
00059 #include "concept.hpp"
00060 #include "_basis.hpp"
00061
00062
00063 #include <generic/base.hpp>
00064
00065
00066
00067
00068 namespace instigate {
00069 namespace stl {
00070 template <typename I1, typename I2, typename T>
00071 T inner_product(I1 b, I1 e, I2 f, T i);
00072
00073 template <typename I1, typename I2, typename T,
00074 typename BF1, typename BF2>
00075 T inner_product(I1 b, I1 e, I2 f, T i, BF1 b1, BF2 b2);
00076 }
00077 }
00078
00118 template <typename I1, typename I2, typename T>
00119 T instigate::stl::inner_product(I1 b, I1 e, I2 f, T i)
00120 {
00121 namespace SP = instigate::stl::single_pass_iterator;
00122 namespace RI = instigate::stl::readable_iterator;
00123 namespace AS = instigate::generic::assignable;
00124 CHECK(SP::requirements<I1>);
00125 CHECK(RI::requirements<I1>);
00126 CHECK(SP::requirements<I2>);
00127 CHECK(RI::requirements<I2>);
00128 CHECK(AS::requirements<T>);
00129 for (; !equal(b, e); increment(b), increment(f)) {
00130 assign(i, i + ((const_dereference(b)) *
00131 (const_dereference(f))));
00132 }
00133 return i;
00134 }
00135
00189 template <typename I1, typename I2, typename T, typename BF1, typename BF2>
00190 T instigate::stl::inner_product(I1 b, I1 e, I2 f, T i, BF1 b1, BF2 b2)
00191 {
00192 namespace SP = instigate::stl::single_pass_iterator;
00193 namespace RI = instigate::stl::readable_iterator;
00194 namespace AS = instigate::generic::assignable;
00195 namespace BFI = instigate::stl::binary_function;
00196 typedef typename RI::interface<I1>::value_type value_type1;
00197 typedef typename RI::interface<I2>::value_type value_type2;
00198 CHECK(SP::requirements<I1>);
00199 CHECK(RI::requirements<I1>);
00200 CHECK(SP::requirements<I2>);
00201 CHECK(RI::requirements<I2>);
00202 CHECK(AS::requirements<T>);
00203 CHECK(BFI::requirements<BF1>);
00204 CHECK(BFI::requirements<BF2>);
00205 typedef typename BFI::interface<BF1>::first_argument_type
00206 first_argument_type1;
00207 typedef typename BFI::interface<BF1>::second_argument_type
00208 second_argument_type1;
00209 typedef typename BFI::interface<BF2>::first_argument_type
00210 first_argument_type2;
00211 typedef typename BFI::interface<BF2>::second_argument_type
00212 second_argument_type2;
00213 typedef typename BFI::interface<BF2>::result_type result_type;
00214 CHECK_CONVERTIBILITY(value_type1, first_argument_type2);
00215 CHECK_CONVERTIBILITY(value_type2, second_argument_type2);
00216 CHECK_CONVERTIBILITY(T, first_argument_type1);
00217 CHECK_CONVERTIBILITY(result_type, second_argument_type1);
00218 CHECK_CONVERTIBILITY(result_type, T);
00219 for (; !equal(b, e); increment(b), increment(f)) {
00220 assign(i, invoke(b1, i, invoke(b2, const_dereference(b),
00221 const_dereference(f))));
00222 }
00223 return i;
00224 }
00225
00226
00227
00228 #endif // INSTIGATE_STL_INNER_PRODUCT_HPP