#include <algorithm>
#include <limits>
#include <numeric>
#include <vector>
#include <iostream>
using namespace std;
template <class T>
void print(T& c){
for( typename T::iterator i = c.begin(); i != c.end(); i++ ){
std::cout << *i << endl;
}
}
int main( )
{
const int n = 8;
vector<unsigned char> pixels1( n, 250 );
vector<int> int_pixels( pixels1.begin(), pixels1.end() );
print( int_pixels);
// create and display the second group of pixels
vector<unsigned char> pixels2( n, 1 );
partial_sum( pixels2.begin(), pixels2.end(), pixels2.begin() );
int_pixels.assign( pixels2.begin(), pixels2.end() );
print( int_pixels);
// perform and display sum with wrap-around
vector<unsigned char> sum( n );
transform( pixels1.begin(), pixels1.end(), pixels2.begin(),sum.begin(), plus<unsigned char>() );
int_pixels.assign( sum.begin(), sum.end() );
print( int_pixels);
}
|