Passing a private method of the class as the compare operator for std::sort
I am writing a code to solve the following problem: Given a set of numbers x[0] , x[1] , ..., x[N-1] , find the permutation that makes them sorted in the ascending order. In the other words, I would like to find a permutation on {0,2,...,N-1} such as i[0] , i[1] , ..., i[N-1] such that x[i[0]] <= x[i[1]] <= ... <= x[i[N-1]] . For this, I have stored the x vector and an index vector i (initially filled with i[j] = j ) as private members of a class. I have also defined a private method as bool MyClass::compare(size_t s, size_t t) { return (x[s] < x[t]); } Now, I would call the std::sort as