template <class Type, int LHold, int RHold, int Left, int Right, bool LlessR> struct InnerQSort_0;template <class Type, int LHold, int RHold, int Left, int Right, bool LnotR>struct InnerQSort_4 { static inline void Go(Type Data[], Type &Pivot) { Data[Right] = Data[Left]; InnerQSort_0<Type,LHold,RHold,Left,Right-1, (Left<(Right-1)) >::Go(Data,Pivot); }};template <class Type, int LHold, int RHold, int Left, int Right>struct InnerQSort_4 <Type, LHold, RHold, Left, Right, false> { static inline void Go(Type Data[], Type &Pivot) { InnerQSort_0<Type,LHold,RHold,Left,Right, (Left<Right) >::Go(Data,Pivot); }};template <class Type, int LHold, int RHold, int Left, int Right, bool LlessR>struct InnerQSort_3 { static inline void Go(Type Data[], Type &Pivot) { if(Data[Left] <= Pivot) InnerQSort_3<Type,LHold,RHold,Left+1,Right, ((Left+1)<Right) >::Go(Data,Pivot); else InnerQSort_4<Type,LHold,RHold,Left,Right, (Left!=Right) >::Go(Data,Pivot); }};template <class Type, int LHold, int RHold, int Left, int Right>struct InnerQSort_3 <Type, LHold, RHold, Left, Right, false> { static inline void Go(Type Data[], Type &Pivot) { InnerQSort_4<Type,LHold,RHold,Left,Right, (Left!=Right) >::Go(Data, Pivot); }};template <class Type, int LHold, int RHold, int Left, int Right, bool LnotR>struct InnerQSort_2 { static inline void Go(Type Data[], Type &Pivot) { Data[Left] = Data[Right]; InnerQSort_3<Type,LHold,RHold,Left+1,Right, ((Left+1)<Right) >::Go(Data,Pivot); }};template <class Type, int LHold, int RHold, int Left, int Right>struct InnerQSort_2 <Type, LHold, RHold, Left, Right, false> { static inline void Go(Type Data[], Type &Pivot) { InnerQSort_3<Type,LHold,RHold,Left,Right, (Left<Right) >::Go(Data,Pivot); }};template <class Type, int LHold, int RHold, int Left, int Right, bool LlessR>struct InnerQSort_1 { static inline void Go(Type Data[], Type &Pivot) { if(Data[Right] >= Pivot) InnerQSort_1<Type,LHold,RHold,Left,Right-1, (Left<(Right-1)) >::Go(Data,Pivot); else InnerQSort_2<Type,LHold,RHold,Left,Right, (Left!=Right) >::Go(Data, Pivot); }};template <class Type, int LHold, int RHold, int Left, int Right>struct InnerQSort_1 <Type, LHold, RHold, Left, Right, false> { static inline void Go(Type Data[], Type &Pivot) { InnerQSort_2<Type,LHold,RHold,Left,Right, (Left!=Right) >::Go(Data, Pivot); }};template <class Type, int LHold, int RHold, int Left, int Right, bool LlessR>struct InnerQSort_0 { static inline void Go(Type Data[], Type &Pivot) { InnerQSort_1<Type,LHold,RHold,Left,Right, (Left<Right) >::Go(Data,Pivot); }};template <class Type, int Left, int Right, bool LlessR> struct InnerQSort;template <class Type, int LHold, int RHold, int Left, int Right>struct InnerQSort_0 <Type, LHold, RHold, Left, Right, false> { static inline void Go(Type Data[], Type &Pivot) { Data[Left] = Pivot; if(LHold < Left) InnerQSort<Type, LHold, Left-1, (LHold<(Left-1)) >::Sort(Data); if(RHold > Left) InnerQSort<Type, Left+1, RHold, ((Left+1)<RHold) >::Sort(Data); }};template <class Type, int Left, int Right, bool LlessR>struct InnerQSort { static inline void Sort(Type Data[]) { Type Pivot = Data[Left]; InnerQSort_0<Type,Left,Right,Left,Right, (Left<Right) >::Go(Data,Pivot); }};template <class Type, int Left, int Right>struct InnerQSort <Type, Left, Right, false> { static inline void Sort(Type Data[]) { }};template <int Size, class Type>struct QuickSort { static inline void Sort(Type Data[]) { InnerQSort<Type,0,Size-1,(0 < (Size-1))>::Sort(Data); }};
I know that it compiles in GCC (G++) 2.95.4 and up. But heed that warning I gave earlier, if you add more than 10 items to be sorted it tags a LOT of memory to compile it. You may also need to add something like this to the command line: -ftemplate-depth-2000 (I think that's the correct switch, I can't remember at the moment).
[edited by - Null and Void on June 3, 2002 9:11:00 PM]