Ask Your Question

gregsmith_to's profile - activity

2015-10-08 21:13:00 -0500 received badge  Necromancer (source)
2015-09-18 08:19:59 -0500 received badge  Enthusiast
2015-09-10 13:23:46 -0500 received badge  Editor (source)
2015-09-10 13:22:16 -0500 answered a question OCV3 replacing static CV_IMPLEMENT_QSORT( icvSortDistances, int, CV_LT )

I suspect it was removed because C++ 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.