#include <iostream>
#include <algorithm>
#include <functional>
#include <boost/iterator/indirect_iterator.hpp>

template<size_t R, size_t C>
void sort_every_col(int (&a)[R][C])
{
    for(size_t c = 0; c < C; ++c)
    {
        int *tmp[R];
        for(size_t r = 0; r < R; ++r)
            tmp[r] = &a[r][c];
        std::sort(boost::make_indirect_iterator(tmp),
                  boost::make_indirect_iterator(tmp+R),
                  std::greater<int>());
    }
}


template<size_t R, size_t C>
void print_array(int (&a)[R][C])
{
    for(size_t r = 0; r < R; ++r)
    {
        for(size_t c = 0; c < C; ++c)
            std::cout << a[r][c] << ' ';
        std::cout << '\n';
    }
}


int main()
{
    int a2[3][3] = {{1, 2, 3},
                    {4, 5, 6},
                    {7, 8, 9}};

    sort_every_col(a2);
    print_array(a2);
}
