2 // Test that class iterators and imperfectly-nested loops work together.
3 // This variant tests initialization by assignment.
5 typedef __PTRDIFF_TYPE__ ptrdiff_t;
12 typedef ptrdiff_t difference_type;
19 T &operator [] (const difference_type &) const;
20 I &operator = (const I &);
25 I &operator += (const difference_type &);
26 I &operator -= (const difference_type &);
27 I operator + (const difference_type &) const;
28 I operator - (const difference_type &) const;
29 friend bool operator == (I &, I &);
30 friend bool operator == (const I &, const I &);
31 friend bool operator < (I &, I &);
32 friend bool operator < (const I &, const I &);
33 friend bool operator <= (I &, I &);
34 friend bool operator <= (const I &, const I &);
35 friend bool operator > (I &, I &);
36 friend bool operator > (const I &, const I &);
37 friend bool operator >= (I &, I &);
38 friend bool operator >= (const I &, const I &);
39 friend typename I::difference_type operator - (I &, I &);
40 friend typename I::difference_type operator - (const I &, const I &);
41 friend I operator + (typename I::difference_type , const I &);
46 I::~I () { p = (T *) 0; }
47 I::I (T *x) : p (x) {}
48 I::I (const I &x) : p (x.p) {}
49 T &I::operator * () { return *p; }
50 T *I::operator -> () { return p; }
51 T &I::operator [] (const difference_type &x) const { return p[x]; }
52 I &I::operator = (const I &x) { p = x.p; return *this; }
53 I &I::operator ++ () { ++p; return *this; }
54 I I::operator ++ (int) { return I (p++); }
55 I &I::operator -- () { --p; return *this; }
56 I I::operator -- (int) { return I (p--); }
57 I &I::operator += (const difference_type &x) { p += x; return *this; }
58 I &I::operator -= (const difference_type &x) { p -= x; return *this; }
59 I I::operator + (const difference_type &x) const { return I (p + x); }
60 I I::operator - (const difference_type &x) const { return I (p - x); }
61 bool operator == (I &x, I &y) { return x.p == y.p; }
62 bool operator == (const I &x, const I &y) { return x.p == y.p; }
63 bool operator != (I &x, I &y) { return !(x == y); }
64 bool operator != (const I &x, const I &y) { return !(x == y); }
65 bool operator < (I &x, I &y) { return x.p < y.p; }
66 bool operator < (const I &x, const I &y) { return x.p < y.p; }
67 bool operator <= (I &x, I &y) { return x.p <= y.p; }
68 bool operator <= (const I &x, const I &y) { return x.p <= y.p; }
69 bool operator > (I &x, I &y) { return x.p > y.p; }
70 bool operator > (const I &x, const I &y) { return x.p > y.p; }
71 bool operator >= (I &x, I &y) { return x.p >= y.p; }
72 bool operator >= (const I &x, const I &y) { return x.p >= y.p; }
73 typename I::difference_type operator - (I &x, I &y) { return x.p - y.p; }
74 typename I::difference_type operator - (const I &x, const I &y) { return x.p - y.p; }
75 I operator + (typename I::difference_type x, const I &y) { return I (x + y.p); }
80 J(const I &x, const I &y) : b (x), e (y) {}
87 const I &J::begin () { return b; }
88 const I &J::end () { return e; }
90 static int f1count[3], f2count[3];
93 extern void abort (void);
95 extern "C" void abort (void);
108 void s1 (J a1, J a2, J a3)
112 #pragma omp for collapse(3)
113 for (i = a1.begin (); i < a1.end (); i++)
116 for (j = a2.begin (); j < a2.end (); j++)
119 for (k = a3.begin (); k < a3.end (); k++)
135 int index[] = {0, 1, 2, 3, 4, 5};
137 J x (&index[0], &index[3]);
138 J y (&index[0], &index[4]);
139 J z (&index[0], &index[5]);
150 /* All intervening code at the same depth must be executed the same
152 if (f1count[0] != f2count[0]) abort ();
153 if (f1count[1] != f2count[1]) abort ();
154 if (f1count[2] != f2count[2]) abort ();
156 /* Intervening code must be executed at least as many times as the loop
158 if (f1count[0] < 3) abort ();
159 if (f1count[1] < 3 * 4) abort ();
161 /* Intervening code must not be executed more times than the number
162 of logical iterations. */
163 if (f1count[0] > 3 * 4 * 5) abort ();
164 if (f1count[1] > 3 * 4 * 5) abort ();
166 /* Check that the innermost loop body is executed exactly the number
167 of logical iterations expected. */
168 if (f1count[2] != 3 * 4 * 5) abort ();