FSF GCC merge 02/23/03
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.jason / template44.C
blob93b47bd23e6ff53d1f2b8ad31f8b3d0afd1efe05
1 #include <stdlib.h>
2 #include <string.h>
4 template <class T>
5 class List {
6 public:
7     int len;
8     T *array;
10     int length() const { return( len ); }
12     List() : len( 0 ), array( 0 ) {}
15 template <class T>
16 int AlgoStdCompare(const T* a, const T* b) {
17   if (*a < *b)
18     return -1;
19   else
20     return (*a > *b);   // 0 if equal, 1 if greater
23 int AlgoStdCompare(const char* const* a, const char * const*b)
25     return strcmp(*a,*b);
27      
28 template <class T>
29 void AlgoFixupSort(List< T >* , int, int ) {
32 template <class T> 
33 void AlgoSort(int (*compare)(const T *, const T *),
34           void (*fixup)( List<T> *, int first, int last),
35           List< T >* theList, int first, int last) {
36   if (last < 0)
37     last = theList->length()-1;
38   
39   qsort(theList->array+first, last-first+1, sizeof(T),
40         (int (*)(const void *, const void *))compare);
41   if (fixup)
42     fixup(theList, first, last);
45 template <class T> 
46 void AlgoSort(List< T >* theList, int first = 0, int last = -1) {
47   int (*compare)(const T*, const T*) = AlgoStdCompare;
48   void (*fixup)( List<T> *, int first, int last) = AlgoFixupSort;
49   
50   AlgoSort(compare, fixup, theList, first, last);
53 int
54 main()
56     List<const char *> slist;
57     AlgoSort( &slist );
59     List<int> ilist;
60     AlgoSort( &ilist );