Hi all.
This template is to add adjacent numbers, but my problem is that the output numbers that come out are "5 7 9 11 6" but I need the output to be with the following numbers "2 5 7 9 11". I hope someone can help me pls. Thnx.
template < typename In, typename Out > Out plus_adj( In first, In last, Out result ) {
if( first == last ) return result ;
*result = *first ;
In prev = first ;
for( ++first, ++result ; first != last ; ++first, ++result ) {
*result = *prev + *first ;
prev = first ;
}
return result ;
}
template < typename In, typename Out > Out plus_adj( In first, In last, Out result ) {
if( first == last ) return result ;
*result = *first ;
auto prev = *first ;
for( ++first, ++result ; first != last ; ++first, ++result ) {
constauto curr = *first ;
*result = prev + curr ;
prev = curr ;
}
return result ;
}