# Revision history [back]

I suspect it was removed because C++ now has the same functionality in std::sort. For the use shown, add (if not already there)

#include <algorithm>


and replace the macro with

 static void
icvSortDistances( int *array, size_t total, int /*unused*/ )
{
std::sort( &array[0], &array[total] );
}


If you want to use the 'aux' parameter (passing info in to the compare) with std::sort, you need to define a little class with a method bool operator ()( T,T) const; you can put data in that class when constructing an instance of it, and you then pass the instance as a 3rd param to std::sort. That sort will call the operator() method to do compares, thus that method will be able to see the data. The operator()( a,b) should implement a<b for your sort - assuming you want increasing results.

Likewise if you want to sort e.g. floats in decreasing abs. value, you can make a little empty class with just the appropriate bool operator( float a , float b )const { return std::abs(a) > std::abs(b);} and pass an instance of that class as the 3rd parameter.

I suspect it was removed because C++ now has long had the same functionality in std::sort. For the use shown, add (if not already there)

#include <algorithm>


and replace the macro with

 static void
icvSortDistances( int *array, size_t total, int /*unused*/ )
{
std::sort( &array[0], &array[total] );
}


If you want to use the 'aux' parameter (passing info in to the compare) with std::sort, you need to define a little class with a method bool operator ()( T,T) const; you can put data in that class when constructing an instance of it, and you then pass the instance as a 3rd param to std::sort. That sort will call the operator() method to do compares, thus that method will be able to see the data. The operator()( a,b) should implement a<b for your sort - assuming you want increasing results.

Likewise if you want to sort e.g. floats in decreasing abs. value, you can make a little empty class with just the appropriate bool operator( float a , float b )const { return std::abs(a) > std::abs(b);} and pass an instance of that class as the 3rd parameter.