2 // Test that template class iterators and imperfectly-nested loops
4 // This variant tests initialization by assignment.
6 typedef __PTRDIFF_TYPE__ ptrdiff_t;
7 extern "C" void abort ();
13 typedef ptrdiff_t difference_type;
20 T &operator [] (const difference_type &) const;
21 I &operator = (const I &);
26 I &operator += (const difference_type &);
27 I &operator -= (const difference_type &);
28 I operator + (const difference_type &) const;
29 I operator - (const difference_type &) const;
30 template <typename S> friend bool operator == (I<S> &, I<S> &);
31 template <typename S> friend bool operator == (const I<S> &, const I<S> &);
32 template <typename S> friend bool operator < (I<S> &, I<S> &);
33 template <typename S> friend bool operator < (const I<S> &, const I<S> &);
34 template <typename S> friend bool operator <= (I<S> &, I<S> &);
35 template <typename S> friend bool operator <= (const I<S> &, const I<S> &);
36 template <typename S> friend bool operator > (I<S> &, I<S> &);
37 template <typename S> friend bool operator > (const I<S> &, const I<S> &);
38 template <typename S> friend bool operator >= (I<S> &, I<S> &);
39 template <typename S> friend bool operator >= (const I<S> &, const I<S> &);
40 template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &);
41 template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &);
42 template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &);
46 template <typename T> I<T>::I () : p (0) {}
47 template <typename T> I<T>::~I () { p = (T *) 0; }
48 template <typename T> I<T>::I (T *x) : p (x) {}
49 template <typename T> I<T>::I (const I &x) : p (x.p) {}
50 template <typename T> T &I<T>::operator * () { return *p; }
51 template <typename T> T *I<T>::operator -> () { return p; }
52 template <typename T> T &I<T>::operator [] (const difference_type &x) const { return p[x]; }
53 template <typename T> I<T> &I<T>::operator = (const I &x) { p = x.p; return *this; }
54 template <typename T> I<T> &I<T>::operator ++ () { ++p; return *this; }
55 template <typename T> I<T> I<T>::operator ++ (int) { return I (p++); }
56 template <typename T> I<T> &I<T>::operator -- () { --p; return *this; }
57 template <typename T> I<T> I<T>::operator -- (int) { return I (p--); }
58 template <typename T> I<T> &I<T>::operator += (const difference_type &x) { p += x; return *this; }
59 template <typename T> I<T> &I<T>::operator -= (const difference_type &x) { p -= x; return *this; }
60 template <typename T> I<T> I<T>::operator + (const difference_type &x) const { return I (p + x); }
61 template <typename T> I<T> I<T>::operator - (const difference_type &x) const { return I (p - x); }
62 template <typename T> bool operator == (I<T> &x, I<T> &y) { return x.p == y.p; }
63 template <typename T> bool operator == (const I<T> &x, const I<T> &y) { return x.p == y.p; }
64 template <typename T> bool operator != (I<T> &x, I<T> &y) { return !(x == y); }
65 template <typename T> bool operator != (const I<T> &x, const I<T> &y) { return !(x == y); }
66 template <typename T> bool operator < (I<T> &x, I<T> &y) { return x.p < y.p; }
67 template <typename T> bool operator < (const I<T> &x, const I<T> &y) { return x.p < y.p; }
68 template <typename T> bool operator <= (I<T> &x, I<T> &y) { return x.p <= y.p; }
69 template <typename T> bool operator <= (const I<T> &x, const I<T> &y) { return x.p <= y.p; }
70 template <typename T> bool operator > (I<T> &x, I<T> &y) { return x.p > y.p; }
71 template <typename T> bool operator > (const I<T> &x, const I<T> &y) { return x.p > y.p; }
72 template <typename T> bool operator >= (I<T> &x, I<T> &y) { return x.p >= y.p; }
73 template <typename T> bool operator >= (const I<T> &x, const I<T> &y) { return x.p >= y.p; }
74 template <typename T> typename I<T>::difference_type operator - (I<T> &x, I<T> &y) { return x.p - y.p; }
75 template <typename T> typename I<T>::difference_type operator - (const I<T> &x, const I<T> &y) { return x.p - y.p; }
76 template <typename T> I<T> operator + (typename I<T>::difference_type x, const I<T> &y) { return I<T> (x + y.p); }
82 J(const I<T> &x, const I<T> &y) : b (x), e (y) {}
89 template <typename T> const I<T> &J<T>::begin () { return b; }
90 template <typename T> const I<T> &J<T>::end () { return e; }
92 static int f1count[3], f2count[3];
95 extern void abort (void);
97 extern "C" void abort (void);
110 template <typename T>
111 void s1 (J<T> a1, J<T> a2, J<T> a3)
115 #pragma omp for collapse(3)
116 for (i = a1.begin (); i < a1.end (); i++)
119 for (j = a2.begin (); j < a2.end (); j++)
122 for (k = a3.begin (); k < a3.end (); k++)
138 int index[] = {0, 1, 2, 3, 4, 5};
140 J<int> x (&index[0], &index[3]);
141 J<int> y (&index[0], &index[4]);
142 J<int> z (&index[0], &index[5]);
153 /* All intervening code at the same depth must be executed the same
155 if (f1count[0] != f2count[0]) abort ();
156 if (f1count[1] != f2count[1]) abort ();
157 if (f1count[2] != f2count[2]) abort ();
159 /* Intervening code must be executed at least as many times as the loop
161 if (f1count[0] < 3) abort ();
162 if (f1count[1] < 3 * 4) abort ();
164 /* Intervening code must not be executed more times than the number
165 of logical iterations. */
166 if (f1count[0] > 3 * 4 * 5) abort ();
167 if (f1count[1] > 3 * 4 * 5) abort ();
169 /* Check that the innermost loop body is executed exactly the number
170 of logical iterations expected. */
171 if (f1count[2] != 3 * 4 * 5) abort ();