#include <type_traits>
#include <vector>
#include <iostream>

namespace
{
    template <typename Container>
    struct value_type_i
    {
        typedef typename std::decay<
            decltype(*std::begin(std::declval<
                Container const &
            >()))
        >::type type;
    };

    template <typename Container>
    using value_type = typename value_type_i<Container>::type;
}

template <typename MatrixType>
MatrixType transpose(MatrixType const & matrix)
{
    auto const nrows = matrix.size();
    auto const ncols = nrows > 0 ? matrix[0].size() : 0;

    MatrixType transposed(ncols, value_type<MatrixType>(nrows));
    for(auto k = 0; k < nrows; ++k)
        for(auto j = 0; j < ncols; ++j)
            transposed[j][k] = matrix[k][j];

    return transposed;
}

template <typename T>
void print(T const & t)
{
	for(auto const & row : t)
	{
		for(auto const & col : row)
			std::cout << col << ' ';
		std::cout << '\n';
	}
	std::cout << '\n';
}

int main()
{
	std::vector<std::vector<int>> A(7, std::vector<int>(9));
	int val = 11;
	for(auto & row : A)
		for(auto & col : row)
			col = val++;
	print(A);
	print(transpose(A));
	
	return 0;
}