| 1 |
// PR tree-optimization/27548 |
| 2 |
// { dg-do compile } |
| 3 |
// { dg-options "-O1 -Wno-return-type" } |
| 4 |
|
| 5 |
namespace Gambit |
| 6 |
{ |
| 7 |
template < class T > class Array |
| 8 |
{ |
| 9 |
protected:int mindex, maxdex; |
| 10 |
T *data; |
| 11 |
int InsertAt (const T & t, int n) |
| 12 |
{ |
| 13 |
T *new_data = new T[++this->maxdex - this->mindex + 1] - this->mindex; |
| 14 |
int i; |
| 15 |
for (i = this->mindex; i <= n - 1; i++) |
| 16 |
new_data[i] = this->data[i]; |
| 17 |
new_data[i++] = t; |
| 18 |
} |
| 19 |
public: Array (unsigned int len = 0):mindex (1), maxdex (len), |
| 20 |
data ((len) ? new T[len] - |
| 21 |
1 : 0) |
| 22 |
{ |
| 23 |
} |
| 24 |
virtual ~ Array () |
| 25 |
{ |
| 26 |
if (maxdex >= mindex) |
| 27 |
delete[](data + mindex); |
| 28 |
} |
| 29 |
const T & operator[] (int index) const |
| 30 |
{ |
| 31 |
} |
| 32 |
int Append (const T & t) |
| 33 |
{ |
| 34 |
return InsertAt (t, this->maxdex + 1); |
| 35 |
} |
| 36 |
}; |
| 37 |
} |
| 38 |
|
| 39 |
class gIndexOdometer |
| 40 |
{ |
| 41 |
private:Gambit::Array < int >MinIndices; |
| 42 |
Gambit::Array < int >CurIndices; |
| 43 |
gIndexOdometer (const Gambit::Array < int >, const Gambit::Array < int >); |
| 44 |
void SetIndex (const int &, const int &); |
| 45 |
int NoIndices () const; |
| 46 |
gIndexOdometer AfterExcisionOf (int &) const; |
| 47 |
}; |
| 48 |
gIndexOdometer |
| 49 |
gIndexOdometer::AfterExcisionOf (int &to_be_zapped) const |
| 50 |
{ |
| 51 |
Gambit::Array < int >NewMins, NewMaxs; |
| 52 |
int i; |
| 53 |
for (i = 1; i <= NoIndices (); i++) |
| 54 |
{ |
| 55 |
NewMins.Append (MinIndices[i]); |
| 56 |
} |
| 57 |
gIndexOdometer NewOdo (NewMins, NewMaxs); |
| 58 |
for (i = 1; i < to_be_zapped; i++) |
| 59 |
NewOdo.SetIndex (i, CurIndices[i]); |
| 60 |
} |