1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include <iostream>
#include <functional>
#include <algorithm>
int main()
{
enum { NROWS = 3, NCOLS = 5, SORT_COL = 1 } ;
typedef int row_type[NCOLS] ;
row_type rows[NROWS] = { { 1, 5, 2, 3, 4 }, { 2, 8, 3, 4, 5 }, { 3, 3, 4, 5, 6 } } ;
std::vector< std::reference_wrapper<row_type> > refs( std::begin(rows), std::end(rows) ) ;
std::sort( refs.begin(), refs.end(),
[] ( const row_type& a, const row_type& b ) { return a[SORT_COL] > b[SORT_COL] ; } ) ;
for( const auto& r : refs )
{
for( int v : r.get() ) std::cout << v << ' ' ;
std::cout << '\n' ;
}
}
|