1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
template< typename InputIter, OutputIter, typename ErrType, typename T >
struct fast_row_sum
{
typedef void result_type;
fast_row_sum( InputIter& ref, OutputIter& out, ErrType& errorSum ) :
ref( ref ), out( out ), errorSum( errorSum )
{ errorSum = ErrType(); }
result_type operator()( const T& value ) const
{
errorSum += abs( value - *ref );
std::cout << "base = " << value << ", ref = " << *ref << ", out = " << *out << std::endl;
++ref;
++out;
}
private:
InputIter& ref;
OutputIter& out;
ErrType& errorSum;
};
int errorSum;
my_out_iter out_iter; // initialize to whatever
my_in_iter in_iter; // initialize to whatever
fast_row_sum< my_in_iter, my_out_iter, int, int > adder( in_iter, out_iter, errorSum );
std::for_each( augBase.begin(), augBase.end(), std::tr1::bind( adder, std::tr1::placeholders::_1 ) );
// inspect errorSum directly for the total error
|