2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.jason / template44.C
blob2aea33a5e05557ec54dbbe6d165237b3b67cfaf3
1 // { dg-do run  }
2 #include <stdlib.h>
3 #include <string.h>
5 template <class T>
6 class List {
7 public:
8     int len;
9     T *array;
11     int length() const { return( len ); }
13     List() : len( 0 ), array( 0 ) {}
16 template <class T>
17 int AlgoStdCompare(const T* a, const T* b) {
18   if (*a < *b)
19     return -1;
20   else
21     return (*a > *b);   // 0 if equal, 1 if greater
24 int AlgoStdCompare(const char* const* a, const char * const*b)
26     return strcmp(*a,*b);
28      
29 template <class T>
30 void AlgoFixupSort(List< T >* , int, int ) {
33 template <class T> 
34 void AlgoSort(int (*compare)(const T *, const T *),
35           void (*fixup)( List<T> *, int first, int last),
36           List< T >* theList, int first, int last) {
37   if (last < 0)
38     last = theList->length()-1;
39   
40   qsort(theList->array+first, last-first+1, sizeof(T),
41         (int (*)(const void *, const void *))compare);
42   if (fixup)
43     fixup(theList, first, last);
46 template <class T> 
47 void AlgoSort(List< T >* theList, int first = 0, int last = -1) {
48   int (*compare)(const T*, const T*) = AlgoStdCompare;
49   void (*fixup)( List<T> *, int first, int last) = AlgoFixupSort;
50   
51   AlgoSort(compare, fixup, theList, first, last);
54 int
55 main()
57     List<const char *> slist;
58     AlgoSort( &slist );
60     List<int> ilist;
61     AlgoSort( &ilist );