Шаблон SortItem предназначен для создания типов удобных для сортировки:
template <class H, class T=H>
struct SortItem
{
H head;
T tail;
SortItem () {}
SortItem ( const H & h ) : head(h) {}
SortItem ( const H & h, const T & t ) : head(h), tail(t) {}
};
template <class H, class T> inline
bool operator < ( const SortItem<H,T> & a, const SortItem<H,T> & b )
{
return a.head < b.head;
}
template <class H, class T> inline
bool operator > ( const SortItem<H,T> & a, const SortItem<H,T> & b )
{
return a.head > b.head;
}
template <class H, class T> inline
bool operator <= ( const SortItem<H,T> & a, const SortItem<H,T> & b )
{
return a.head <= b.head;
}
template <class H, class T> inline
bool operator >= ( const SortItem<H,T> & a, const SortItem<H,T> & b )
{
return a.head >= b.head;
}
template <class H, class T> inline
bool operator == ( const SortItem<H,T> & a, const SortItem<H,T> & b )
{
return a.head == b.head;
}
template <class H, class T> inline
bool operator != ( const SortItem<H,T> & a, const SortItem<H,T> & b )
{
return a.head != b.head;
}
Поле head служит для сравнения элементов, а поле tail содержит связанную с ним информацию. Исходники находятся в файле template.h. Наверх |