#include <vector> #include <algorithm> using namespace std; vector< MyStruct > values; sort( values.begin( ), values.end( ), [ ]( const MyStruct& lhs, const MyStruct& rhs ) { return lhs.key < rhs.key; });