1 // { dg-do run }
2
3 #include <string>
4 #include <cstdlib>
5
6 template <typename T>
7 class J
8 {
9 public:
10 typedef typename std::basic_string<T>::iterator iterator;
J(const iterator & x,const iterator & y)11 J(const iterator &x, const iterator &y) : b (x), e (y) {}
12 const iterator &begin ();
13 const iterator &end ();
14 private:
15 iterator b, e;
16 };
17
18 template <typename T>
begin()19 const typename std::basic_string<T>::iterator &J<T>::begin () { return b; }
20 template <typename T>
end()21 const typename std::basic_string<T>::iterator &J<T>::end () { return e; }
22
23 template <typename T>
24 void
baz(T & i)25 baz (T &i)
26 {
27 if (*i < L'a' || *i >= L'a' + 2000)
28 std::abort ();
29 (*i)++;
30 }
31
32 void
f1(const std::basic_string<wchar_t>::iterator & x,const std::basic_string<wchar_t>::iterator & y)33 f1 (const std::basic_string<wchar_t>::iterator &x,
34 const std::basic_string<wchar_t>::iterator &y)
35 {
36 #pragma omp parallel
37 #pragma omp single
38 #pragma omp taskloop
39 for (std::basic_string<wchar_t>::iterator i = x; i <= y; i += 6)
40 baz (i);
41 }
42
43 void
f2(const std::basic_string<wchar_t>::iterator & x,const std::basic_string<wchar_t>::iterator & y)44 f2 (const std::basic_string<wchar_t>::iterator &x,
45 const std::basic_string<wchar_t>::iterator &y)
46 {
47 std::basic_string<wchar_t>::iterator i;
48 #pragma omp parallel
49 #pragma omp single
50 #pragma omp taskloop private(i)
51 for (i = x; i < y - 1; i = 1 - 6 + 7 + i)
52 baz (i);
53 }
54
55 template <typename T>
56 void
f3(const std::basic_string<wchar_t>::iterator & x,const std::basic_string<wchar_t>::iterator & y)57 f3 (const std::basic_string<wchar_t>::iterator &x,
58 const std::basic_string<wchar_t>::iterator &y)
59 {
60 #pragma omp parallel
61 #pragma omp single
62 #pragma omp taskloop
63 for (std::basic_string<wchar_t>::iterator i = x; i <= y; i = i + 9 - 8)
64 baz (i);
65 }
66
67 template <typename T>
68 void
f4(const std::basic_string<wchar_t>::iterator & x,const std::basic_string<wchar_t>::iterator & y)69 f4 (const std::basic_string<wchar_t>::iterator &x,
70 const std::basic_string<wchar_t>::iterator &y)
71 {
72 std::basic_string<wchar_t>::iterator i;
73 #pragma omp parallel
74 #pragma omp single
75 #pragma omp taskloop lastprivate(i)
76 for (i = x + 2000 - 64; i > y + 10; --i)
77 baz (i);
78 }
79
80 void
f5(const std::basic_string<wchar_t>::iterator & x,const std::basic_string<wchar_t>::iterator & y)81 f5 (const std::basic_string<wchar_t>::iterator &x,
82 const std::basic_string<wchar_t>::iterator &y)
83 {
84 #pragma omp parallel
85 #pragma omp single
86 #pragma omp taskloop
87 for (std::basic_string<wchar_t>::iterator i = x + 2000 - 64;
88 i > y + 10; i -= 10)
89 baz (i);
90 }
91
92 template <int N>
93 void
f6(const std::basic_string<wchar_t>::iterator & x,const std::basic_string<wchar_t>::iterator & y)94 f6 (const std::basic_string<wchar_t>::iterator &x,
95 const std::basic_string<wchar_t>::iterator &y)
96 {
97 #pragma omp parallel
98 #pragma omp single
99 #pragma omp taskloop
100 for (std::basic_string<wchar_t>::iterator i = x + 2000 - 64;
101 i > y + 10; i = i - 12 + 2)
102 {
103 std::basic_string<wchar_t>::iterator j = i + N;
104 baz (j);
105 }
106 }
107
108 template <int N>
109 void
f7(std::basic_string<wchar_t>::iterator i,const std::basic_string<wchar_t>::iterator & x,const std::basic_string<wchar_t>::iterator & y)110 f7 (std::basic_string<wchar_t>::iterator i,
111 const std::basic_string<wchar_t>::iterator &x,
112 const std::basic_string<wchar_t>::iterator &y)
113 {
114 #pragma omp parallel
115 #pragma omp single
116 #pragma omp taskloop
117 for (i = x - 10; i <= y + 10; i += N)
118 baz (i);
119 }
120
121 template <wchar_t N>
122 void
f8(J<wchar_t> j)123 f8 (J<wchar_t> j)
124 {
125 std::basic_string<wchar_t>::iterator i;
126 #pragma omp parallel
127 #pragma omp single
128 #pragma omp taskloop
129 for (i = j.begin (); i <= j.end () + N; i += 2)
130 baz (i);
131 }
132
133 template <typename T, int N>
134 void
f9(const typename std::basic_string<T>::iterator & x,const typename std::basic_string<T>::iterator & y)135 f9 (const typename std::basic_string<T>::iterator &x,
136 const typename std::basic_string<T>::iterator &y)
137 {
138 #pragma omp parallel
139 #pragma omp single
140 #pragma omp taskloop
141 for (typename std::basic_string<T>::iterator i = x; i <= y; i = i + N)
142 baz (i);
143 }
144
145 template <typename T, int N>
146 void
f10(const typename std::basic_string<T>::iterator & x,const typename std::basic_string<T>::iterator & y)147 f10 (const typename std::basic_string<T>::iterator &x,
148 const typename std::basic_string<T>::iterator &y)
149 {
150 typename std::basic_string<T>::iterator i;
151 #pragma omp parallel
152 #pragma omp single
153 #pragma omp taskloop
154 for (i = x; i > y; i = i + N)
155 baz (i);
156 }
157
158 template <typename T>
159 void
f11(const T & x,const T & y)160 f11 (const T &x, const T &y)
161 {
162 #pragma omp parallel
163 {
164 #pragma omp single nowait
165 #pragma omp taskloop nogroup
166 for (T i = x; i <= y; i += 3)
167 baz (i);
168 #pragma omp single nowait
169 {
170 T j = y + 3;
171 baz (j);
172 }
173 }
174 }
175
176 template <typename T>
177 void
f12(const T & x,const T & y)178 f12 (const T &x, const T &y)
179 {
180 T i;
181 #pragma omp parallel
182 #pragma omp single
183 #pragma omp taskloop private(i)
184 for (i = x; i > y; --i)
185 baz (i);
186 }
187
188 template <int N>
189 struct K
190 {
191 template <typename T>
192 static void
f13K193 f13 (const T &x, const T &y)
194 {
195 #pragma omp parallel
196 #pragma omp single
197 #pragma omp taskloop
198 for (T i = x; i <= y + N; i += N)
199 baz (i);
200 }
201 };
202
203 #define check(expr) \
204 for (int i = 0; i < 2000; i++) \
205 if (expr) \
206 { \
207 if (a[i] != L'a' + i + 1) \
208 std::abort (); \
209 a[i] = L'a' + i; \
210 } \
211 else if (a[i] != L'a' + i) \
212 std::abort ()
213
214 int
main()215 main ()
216 {
217 std::basic_string<wchar_t> a = L"";
218 for (int i = 0; i < 2000; i++)
219 a += L'a' + i;
220 f1 (a.begin () + 10, a.begin () + 1990);
221 check (i >= 10 && i <= 1990 && (i - 10) % 6 == 0);
222 f2 (a.begin () + 0, a.begin () + 1999);
223 check (i < 1998 && (i & 1) == 0);
224 f3<char> (a.begin () + 20, a.begin () + 1837);
225 check (i >= 20 && i <= 1837);
226 f4<int> (a.begin () + 0, a.begin () + 30);
227 check (i > 40 && i <= 2000 - 64);
228 f5 (a.begin () + 0, a.begin () + 100);
229 check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0);
230 f6<-10> (a.begin () + 10, a.begin () + 110);
231 check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0);
232 f7<6> (std::basic_string<wchar_t>::iterator (), a.begin () + 12,
233 a.begin () + 1800);
234 check (i >= 2 && i <= 1808 && (i - 2) % 6 == 0);
235 f8<121> (J<wchar_t> (a.begin () + 14, a.begin () + 1803));
236 check (i >= 14 && i <= 1924 && (i & 1) == 0);
237 f9<wchar_t, 7> (a.begin () + 33, a.begin () + 1967);
238 check (i >= 33 && i <= 1967 && (i - 33) % 7 == 0);
239 f10<wchar_t, -7> (a.begin () + 1939, a.begin () + 17);
240 check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0);
241 f11<std::basic_string<wchar_t>::iterator > (a.begin () + 16,
242 a.begin () + 1981);
243 check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0);
244 f12<std::basic_string<wchar_t>::iterator > (a.begin () + 1761,
245 a.begin () + 37);
246 check (i > 37 && i <= 1761);
247 K<5>::f13<std::basic_string<wchar_t>::iterator > (a.begin () + 1,
248 a.begin () + 1935);
249 check (i >= 1 && i <= 1936 && (i - 1) % 5 == 0);
250 }
251