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 31 32
|
#include <iostream>
#include <iterator>
#include <array>
#include <vector>
#include <deque>
#include <cmath>
#include <sstream>
template < typename RANDOM_ACCESS_ITERATOR >
void foo( RANDOM_ACCESS_ITERATOR begin, RANDOM_ACCESS_ITERATOR end )
{
auto N = end - begin ;
for( decltype(N) i = 0 ; i < N ; ++i ) begin[i] *= (i+1) ;
for( ; begin != end ; ++begin ) std::cout << std::llround(*begin) << ' ' ;
std::cout << '\n' ;
}
int main()
{
double a[] = { -1.62, -1.49, -0.63, -0.33, 0, 0.33, 0.63, 1.49, 1.62 };
foo( std::begin(a), std::end(a) ) ;
std::array<double,9> b = { { -1.62, -1.49, -0.63, -0.33, 0, 0.33, 0.63, 1.49, 1.62 } };
foo( std::begin(b), std::end(b) ) ;
std::vector<double> c = { -1.62, -1.49, -0.63, -0.33, 0, 0.33, 0.63, 1.49, 1.62 };
foo( std::begin(c), std::end(c) ) ;
std::deque<double> d = { -1.62, -1.49, -0.63, -0.33, 0, 0.33, 0.63, 1.49, 1.62 };
foo( std::begin(d), std::end(d) ) ;
}
|