OSDN Git Service

* gcc.c-torture/execute/20020720-1.x: Fix m32r target selector to be a proper
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.old-deja / g++.jason / template44.C
1 // { dg-do run  }
2 #include <stdlib.h>
3 #include <string.h>
4
5 template <class T>
6 class List {
7 public:
8     int len;
9     T *array;
10
11     int length() const { return( len ); }
12
13     List() : len( 0 ), array( 0 ) {}
14 };
15
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
22 }
23
24 int AlgoStdCompare(const char* const* a, const char * const*b)
25 {
26     return strcmp(*a,*b);
27 }
28      
29 template <class T>
30 void AlgoFixupSort(List< T >* , int, int ) {
31 }
32
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);
44 }
45
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);
52 }
53
54 int
55 main()
56 {
57     List<const char *> slist;
58     AlgoSort( &slist );
59
60     List<int> ilist;
61     AlgoSort( &ilist );
62 }