OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc1/] [gcc/] [testsuite/] [g++.old-deja/] [g++.jason/] [template44.C] - Blame information for rev 779

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 305 jeremybenn
// { dg-do run  }
2
#include 
3
#include 
4
 
5
template 
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 
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 
30
void AlgoFixupSort(List< T >* , int, int ) {
31
}
32
 
33
template 
34
void AlgoSort(int (*compare)(const T *, const T *),
35
          void (*fixup)( List *, 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 
47
void AlgoSort(List< T >* theList, int first = 0, int last = -1) {
48
  int (*compare)(const T*, const T*) = AlgoStdCompare;
49
  void (*fixup)( List *, int first, int last) = AlgoFixupSort;
50
 
51
  AlgoSort(compare, fixup, theList, first, last);
52
}
53
 
54
int
55
main()
56
{
57
    List slist;
58
    AlgoSort( &slist );
59
 
60
    List ilist;
61
    AlgoSort( &ilist );
62
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.