74 #ifndef SLIP_STL_NUMERIC_EXT_HPP
75 #define SLIP_STL_NUMERIC_EXT_HPP
124 template<
typename _InputIterator1,
typename _InputIterator2,
125 typename _MaskIterator,
129 _MaskIterator mask_first,
130 _InputIterator2 first2, _Tp init,
131 typename std::iterator_traits<_MaskIterator>::value_type value=
typename std::iterator_traits<_MaskIterator>::value_type(1))
133 assert(first1 != last1);
135 for (; first1 != last1; ++first1, ++first2, ++mask_first)
137 if(*mask_first == value)
139 init = init + (*first1 * *first2);
202 template<
typename _InputIterator1,
typename _InputIterator2,
203 typename _MaskIterator,
205 typename _BinaryOperation1,
typename _BinaryOperation2>
208 _MaskIterator mask_first,
209 _InputIterator2 first2, _Tp init,
210 _BinaryOperation1 binary_op1,
211 _BinaryOperation2 binary_op2,
212 typename std::iterator_traits<_MaskIterator>::value_type value=
typename std::iterator_traits<_MaskIterator>::value_type(1))
215 assert(first1 != last1);
217 for (; first1 != last1; ++first1, ++first2, ++mask_first)
219 if(*mask_first == value)
221 init = binary_op1(init, binary_op2(*first1, *first2));
271 template<
typename _InputIterator1,
typename _InputIterator2,
276 _InputIterator2 first2, _Tp init,
279 assert(first1 != last1);
281 for (; first1 != last1; ++first1, ++first2)
285 init = init + (*first1 * *first2);
336 template<
typename _InputIterator1,
typename _InputIterator2,
338 typename _BinaryOperation1,
typename _BinaryOperation2,
342 _InputIterator2 first2, _Tp init,
343 _BinaryOperation1 binary_op1,
344 _BinaryOperation2 binary_op2,
348 assert(first1 != last1);
350 for (; first1 != last1; ++first1, ++first2)
354 init = binary_op1(init, binary_op2(*first1, *first2));
363 #endif //SLIP_STL_NUMERIC_EXT_HPP
_Tp inner_product_mask(_InputIterator1 first1, _InputIterator1 last1, _MaskIterator mask_first, _InputIterator2 first2, _Tp init, typename std::iterator_traits< _MaskIterator >::value_type value=typename std::iterator_traits< _MaskIterator >::value_type(1))
Compute inner product of two ranges according to a mask range.
_Tp inner_product_if(_InputIterator1 first1, _InputIterator1 last1, _InputIterator2 first2, _Tp init, _Predicate pred)
Compute inner product of two ranges according to a Predicate.