V
velthuijsen
The STL sort only accepts a function that is defined in the form of
bool Fname(<type>, <type>) in which <type> is the type of range to be
sorted.
I'm looking for a way to be able to sort the range on a different set
of types then the range.
I currently have worked out a way to do it (see code below) but it
seems fairly involved and I was wondering if there is a better way of
doing it?
Point.h contains a simple struct plus a few basic operations on this
struct.
PointUtility.h contains advanced functions that work with the Point
struct.
Header:
#include "Point.h"
class MySort
{
public:
static void Sort(int *Begin, int *End, const Point *Argument);
static bool Compare(int Left, int Right);
private:
static const Point *Points;
};
CPP:
#include "MySort.h"
#include "PointUtility.h"
#include <algorithm>
const Point* MySort:oints = 0;
void MySort::Sort(int *Begin, int *End, const Point *Argument)
{
Points = Argument;
std::sort(Begin, End, MySort::Compare);
Points = 0;
}
bool MySort::Compare(int Left, int Right)
{
return PointCompareXYorder(Points
bool Fname(<type>, <type>) in which <type> is the type of range to be
sorted.
I'm looking for a way to be able to sort the range on a different set
of types then the range.
I currently have worked out a way to do it (see code below) but it
seems fairly involved and I was wondering if there is a better way of
doing it?
Point.h contains a simple struct plus a few basic operations on this
struct.
PointUtility.h contains advanced functions that work with the Point
struct.
Header:
#include "Point.h"
class MySort
{
public:
static void Sort(int *Begin, int *End, const Point *Argument);
static bool Compare(int Left, int Right);
private:
static const Point *Points;
};
CPP:
#include "MySort.h"
#include "PointUtility.h"
#include <algorithm>
const Point* MySort:oints = 0;
void MySort::Sort(int *Begin, int *End, const Point *Argument)
{
Points = Argument;
std::sort(Begin, End, MySort::Compare);
Points = 0;
}
bool MySort::Compare(int Left, int Right)
{
return PointCompareXYorder(Points
, Points
);
}
}