Thanks in advance.
Code:
# include <vector>
# include <algorithm>
using namespace std; // this is bad but only here for test purposes
template <typename T>
void transpose(std::vector<T>& input,
std::vector<T>& output) // these probably need to be const correct
{
for ( size_t idx (0); idx < input.size(); ++idx )
{
//output [ idx + 1 ] = input [ idx + 1 ];
}
}
int main()
{
int in_arr [ 3 ] [ 3 ];
int out_arr [ 3 ] [ 3 ];
// initialize arr;
int temp ( 4 );
for ( int idx ( 0 ); idx < 3; ++idx )
for ( int jdx ( 0 ); jdx < 3; ++jdx )
in_arr [ idx ] [ jdx ] = temp * jdx;
// dump in
for ( int idx ( 0 ); idx < 3; ++idx )
for ( int jdx ( 0 ); jdx < 3; ++jdx )
cout << " " << in_arr [ idx ][ jdx ] << endl;
cout << endl;
// transpose
for ( int idx ( 0 ); idx < 3; ++idx )
for ( int jdx ( 0 ); jdx < 3; ++jdx )
out_arr [ jdx ][ idx ] = in_arr [ idx ] [ jdx ];
// dump
for ( int idx ( 0 ); idx < 3; ++idx )
for ( int jdx ( 0 ); jdx < 3; ++jdx )
cout << " " << out_arr [ idx ][ jdx ] << endl;
// now do the same with a vector
vector<double> in;
in.push_back ( 0 );
in.push_back ( 4 );
in.push_back ( 8 );
in.push_back ( 0 );
in.push_back ( 4 );
in.push_back ( 8 );
in.push_back ( 0 );
in.push_back ( 4 );
in.push_back ( 8 );
vector<double> out;
transpose<double> ( in, out );
std::copy ( out.begin(), out.end(),
std::ostream_iterator<double> ( std::cout, "\n" ));
}

