Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
26.valarray.cassign.cpp
Go to the documentation of this file.
1
29#include <cstdlib> // for free(), strtod(), size_t
30#include <valarray> // for indirect_array, valarray
31
32#include <rw_value.h> // for UserClass
33#include <rw_driver.h> // for rw_test()
34#include <rw_printf.h> // for rw_asnprintf()
35
36
38// returns an array of size elements of type T constructed from a string
39// of comma-separated values
40template <class T>
41T*
42make_array (const T*, const char *s, std::size_t *psize)
43{
44 std::size_t bufsize = 0; // capacity of buffer
45 std::size_t nelems = 0; // number of elements in buffer
46
47 if (psize)
48 *psize = 0;
49
50 if (0 == s)
51 s = "";
52
53 T* buf = 0;
54
55 while (*s) {
56
57 // get the next value from the string
58 char *end = 0;
59 const double val = std::strtod (s, &end);
60
61 unsigned long repeat = 1;
62
63 if ('@' == *end) {
64 // process repeat directive (e.g., "123@5" expands into
65 // 5 copies of the number 123)
66 char *e = 0;
67 repeat = std::strtoul (++end, &e, 10);
68
69 // skip trailing whitespace
70 for (; ' ' == *end; ++end);
71
72 // the next character must be either a NUL or comma
73 RW_ASSERT ('\0' == *e || ',' == *e);
74
75 if (',' == *e)
76 ++e;
77
78 s = e;
79 }
80 else {
81 // skip trailing whitespace
82 for (; ' ' == *end; ++end);
83
84 // the next character must be NUL or a comma
85 RW_ASSERT ('\0' == *end || ',' == *end);
86 s = end;
87
88 if (*s)
89 ++s;
90 }
91
92 while (repeat--) {
93
94 if (nelems == bufsize) {
95 // reallocate buffer
96
97 const std::size_t newsize = (bufsize + 1) * 2;
98 T* const tmp = new T [newsize];
99
100 // copy data to the newly allocated buffer
101 for (std::size_t i = 0; i != nelems; ++i)
102 tmp [i] = buf [i];
103
104 // increase the capacity
105 bufsize = newsize;
106
107 // deallocate old buffer
108 delete[] buf;
109 buf = tmp;
110 }
111
112 // append value to the end of the buffer
113 buf [nelems++] = T (val);
114 }
115 }
116
117 if (psize)
118 *psize = nelems;
119
120 return buf;
121}
122
123
124// deletes an array of elements of type T returned from make_array
125template <class T>
126void
127delete_array (const T *array, std::size_t)
128{
129 T* const a = _RWSTD_CONST_CAST (T*, array);
130 delete[] a;
131}
132
133
134template <class T>
135const std::size_t* count (const T*) { return 0; }
136
137
138template <class T>
139T value (const T &val) { return val; }
140
141
143// deletes an array of elements of type T returned from make_array
144void
145delete_array (const UserClass *array, std::size_t nelems)
146{
148
149 for (std::size_t i = 0; i != nelems; ++i)
150 (a + i)->~UserClass ();
151
152 operator delete (a);
153}
154
155
156// returns an array of size elements of type UserClass
157// constructed from a string of comma-separated values
159make_array (const UserClass*, const char *s, std::size_t *psize)
160{
161 std::size_t bufsize = 0; // capacity of buffer
162 std::size_t nelems = 0; // number of elements in buffer
163
164 if (psize)
165 *psize = 0;
166
167 if (0 == s)
168 s = "";
169
170 UserClass* buf = 0;
171
172 while (*s) {
173
174 // get the next value from the string
175 char *end = 0;
176 const double val = std::strtod (s, &end);
177
178 unsigned long repeat = 1;
179
180 if ('@' == *end) {
181 // process repeat directive (e.g., "123@5" expands into
182 // 5 copies of the number 123)
183 char *e = 0;
184 repeat = std::strtoul (++end, &e, 10);
185
186 // skip trailing whitespace
187 for (; ' ' == *end; ++end);
188
189 // the next character must be either a NUL or comma
190 RW_ASSERT ('\0' == *e || ',' == *e);
191
192 if (',' == *e)
193 ++e;
194
195 s = e;
196 }
197 else {
198 // skip trailing whitespace
199 for (; ' ' == *end; ++end);
200
201 // the next character must be NUL or a comma
202 RW_ASSERT ('\0' == *end || ',' == *end);
203
204 s = end;
205 if (*s)
206 ++s;
207 }
208
209 while (repeat--) {
210
211 if (nelems == bufsize) {
212 static const std::size_t size = sizeof (UserClass);
213
214 void* const raw = operator new ((bufsize + 1) * 2 * size);
215 UserClass* const tmp = _RWSTD_STATIC_CAST (UserClass*, raw);
216
217 for (std::size_t i = 0; i != nelems; ++i)
218 new (tmp +i) UserClass (buf [i]);
219
220 bufsize = (bufsize + 1) * 2;
221
222 delete_array (buf, nelems);
223 buf = tmp;
224 }
225
226 new (buf + nelems) UserClass ();
227 buf [nelems].data_.val_ = int (val);
228 ++nelems;
229 }
230 }
231
232 if (psize)
233 *psize = nelems;
234
235 return buf;
236}
237
238
239const std::size_t* count (const UserClass*) { return &UserClass::count_; }
240
241int value (const UserClass &val) { return val.data_.val_; }
242
243
245template <class T>
246void
248 std::valarray<T>&
249 (std::valarray<T>::*op_assign)(const std::valarray<T>&),
250 const char *tname, // T's type name
251 const char *opname, // which assignment operator
252 int line, // test case line number
253 const char *lhs_str, // left hand side of assignment
254 const char *rhs_str, // right hand side of assignment
255 const char *res_str) // result of assignment
256{
257 std::size_t nelems = 0;
258 std::size_t tmp;
259
260 // create an array of values of type T from the string lhs_str
261 // representing the left-hand side argument of the assignment
262 const T* const lhs_array = make_array ((const T*)0, lhs_str, &nelems);
263
264 // create an array of values of type T from the string rhs_str
265 // representing the right-hand side argument of the assignment
266 const T* const rhs_array = make_array ((const T*)0, rhs_str, &tmp);
267
268 // both arguments of the assignment must have the same size
269 RW_ASSERT (tmp == nelems);
270
271 // create an array of values of type T from the string res_str
272 // representing the result of the assignment
273 const T* const res_array = make_array ((const T*)0, res_str, &tmp);
274
275 // the result of the assignment must have the same size as both
276 // arguments
277 RW_ASSERT (tmp == nelems);
278
279 // construct valarray arguments from the arrays created above
280 /* const */ std::valarray<T> lhs_va (lhs_array, nelems);
281 const std::valarray<T> rhs_va (rhs_array, nelems);
282
283 char* fname = 0;
284 std::size_t size = 0;
285
286 // pointer to a counter keeping track of all objects of type T
287 // in existence (non-null only for T=UserClass)
288 const std::size_t* const pcounter = count ((const T*)0);
289
290 // get the number of objects of type T (only possible for user
291 // defined T) before invoking the operator
292 std::size_t nobjects = pcounter ? *pcounter : 0;
293
294 // format the name of the function call to be used in diagnostic
295 // messages below
296 rw_asnprintf (&fname, &size,
297 "valarray<%s>(%s) %s std::valarray<%1$s>(%s)",
298 tname, lhs_str, opname, rhs_str);
299
300 // invoke the assignment operator through the member pointer
301 std::valarray<T> &res = (lhs_va.*op_assign)(rhs_va);
302
303 // verify that the resturned reference refers to the assignee
304 rw_assert (&res == &lhs_va, 0, line,
305 "line %d == %#p, got %#p",
306 __LINE__, fname, &lhs_va, &res);
307
308
309 // verify the size of the array
310 rw_assert (lhs_va.size () == nelems, 0, line,
311 "line %d. %s.size() == %zu, got %zu",
312 __LINE__, fname, nelems, lhs_va.size ());
313
314 if (pcounter) {
315 // verify that the assignment didn't leak any objects
316 nobjects = *pcounter - nobjects;
317
318 rw_assert (0 == nobjects, 0, line,
319 "line %d. %s constucted %zu objects, expected %zu",
320 __LINE__, fname, nobjects, nelems);
321 }
322
323 // verify the element values
324 for (std::size_t i = 0; i != nelems; ++i) {
325 if (!rw_assert (lhs_va [i] == res_array [i], 0, line,
326 "line %d. %s: element at index %zu == %d, got %d",
327 __LINE__, fname, i, value (res_array [i]),
328 value (lhs_va [i])))
329 break;
330
331 }
332
333 delete_array (lhs_array, nelems);
334 delete_array (rhs_array, nelems);
335
336 std::free (fname);
337}
338
339
340
342#define OP(lhs, rhs, res) \
343 test_op_assign ((T*)0, op, tname, opname, __LINE__, lhs, rhs, res)
344
345
346template <class T>
347void test_mul_assign (const T*, const char *tname, const char *opname)
348{
349 rw_info (0, 0, __LINE__,
350 "std::valarray<%s>::operator%s (const std::valarray<%1$s>&)",
351 tname, opname);
352
353 std::valarray<T>& (std::valarray<T>::*op)(const std::valarray<T>&) =
354 &std::valarray<T>::operator*=;
355
356 OP ("", "", "");
357
358 OP ("0", "0", "0");
359 OP ("0", "1", "0");
360 OP ("1", "0", "0");
361 OP ("1", "1", "1");
362 OP ("1", "2", "2");
363
364 OP ("1,2", "1,1", "1,2");
365 OP ("1,2", "1,2", "1,4");
366 OP ("2,3", "4,5", "8,15");
367 OP ("3,4", "5,6", "15,24");
368
369 OP ("1,2,3", "4,5,6", "4,10,18");
370 OP ("-1,-2,-3", "-4,-5,-6", "4,10,18");
371 OP ("1,-2,3", "-4,5,-6", "-4,-10,-18");
372}
373
374
376template <class T>
377void test_div_assign (const T*, const char *tname, const char *opname)
378{
379 rw_info (0, 0, __LINE__,
380 "std::valarray<%s>::operator%s (const std::valarray<%1$s>&)",
381 tname, opname);
382
383 std::valarray<T>& (std::valarray<T>::*op)(const std::valarray<T>&) =
384 &std::valarray<T>::operator/=;
385
386 OP ("", "", "");
387
388 OP ("0", "1", "0");
389 OP ("1", "1", "1");
390 OP ("2", "1", "2");
391 OP ("2", "2", "1");
392 OP ("3", "1", "3");
393 OP ("3", "2", "1.5");
394 OP ("4", "2", "2");
395
396 OP ("0,1,2,3,4,5,6,7", "1,1,1,1,1,1,1,1", "0,1,2,3,4,5,6,7");
397 OP ("2,4,6,8,10,12,14,16", "2,2,2,2,2,2,2,2", "1,2,3,4,5,6,7,8");
398 OP ("2,4,6,8,10,12,14,16", "2,2,2,2,2,2,2,2", "1,2,3,4,5,6,7,8");
399
400 OP ("0@127", "1@127", "0@127");
401 OP ("1@128", "1@128", "1@128");
402 OP ("2@255", "1@255", "2@255");
403 OP ("2@256", "2@256", "1@256");
404 OP ("3@256", "1@256", "3@256");
405 OP ("3@511", "2@511", "1.5@511");
406 OP ("4@512", "2@512", "2@512");
407}
408
409
411template <class T>
412void test_mod_assign (const T*, const char *tname, const char *opname)
413{
414 rw_info (0, 0, __LINE__,
415 "std::valarray<%s>::operator%s (const std::valarray<%1$s>&)",
416 tname, opname);
417
418 std::valarray<T>& (std::valarray<T>::*op)(const std::valarray<T>&) =
419 &std::valarray<T>::operator%=;
420
421 OP ("", "", "");
422
423 OP ("0", "1", "0");
424 OP ("1", "1", "0");
425 OP ("2", "1", "0");
426 OP ("2", "2", "0");
427 OP ("3", "1", "0");
428 OP ("3", "2", "1");
429 OP ("3", "3", "0");
430 OP ("4", "1", "0");
431 OP ("4", "2", "0");
432 OP ("4", "3", "1");
433 OP ("4", "4", "0");
434
435 OP ("0,1", "2,2", "0,1");
436 OP ("1,2,3", "4,4,4", "1,2,3");
437 OP ("2,3,4,5", "6,6,6,6", "2,3,4,5");
438
439 OP ("0,1,2,3,4,5,6,7,8,9", "10,9,8,7,6,5,4,3,2,1", "0,1,2,3,4,0,2,1,0,0");
440}
441
442#define CANNOT_TEST(T, name) \
443 void test_##name (const T*, const char*, const char*) { } \
444 typedef void swallow_semicolon
445
446
447CANNOT_TEST (float, mod_assign);
448CANNOT_TEST (double, mod_assign);
449CANNOT_TEST (UserClass, mod_assign);
450
451
453template <class T>
454void test_add_assign (const T*, const char *tname, const char *opname)
455{
456 rw_info (0, 0, __LINE__,
457 "std::valarray<%s>::operator%s (const std::valarray<%1$s>&)",
458 tname, opname);
459
460 std::valarray<T>& (std::valarray<T>::*op)(const std::valarray<T>&) =
461 &std::valarray<T>::operator+=;
462
463 OP ("", "", "");
464
465 OP ("0", "0", "0");
466 OP ("0", "1", "1");
467 OP ("1", "0", "1");
468 OP ("1", "-1", "0");
469 OP ("-1", "1", "0");
470
471 OP ("0@31", "0@31", "0@31");
472 OP ("0@31", "1@31", "1@31");
473 OP ("1@31", "0@31", "1@31");
474 OP ("1@31", "-1@31", "0@31");
475 OP ("-1@31", "1@31", "0@31");
476
477 OP ("2@32", "3@32", "5@32");
478 OP ("3@32", "5@32", "8@32");
479 OP ("5@32", "7@32", "12@32");
480 OP ("9@32", "-9@32", "0@32");
481
482 OP ("0@63", "0@63", "0@63");
483 OP ("0@63", "1@63", "1@63");
484 OP ("1@63", "0@63", "1@63");
485 OP ("1@63", "-1@63", "0@63");
486 OP ("-1@63", "1@63", "0@63");
487
488 OP ("0@63", "0@63", "0@63");
489 OP ("0@63", "1@63", "1@63");
490 OP ("1@63", "0@63", "1@63");
491 OP ("1@63", "-1@63", "0@63");
492 OP ("-1@63", "1@63", "0@63");
493
494 OP ("0,0", "0,0", "0,0");
495 OP ("0,0", "0,1", "0,1");
496 OP ("0,0", "1,0", "1,0");
497 OP ("0,0", "1,1", "1,1");
498 OP ("0,1", "0,1", "0,2");
499 OP ("0,1", "1,0", "1,1");
500 OP ("0,1", "1,1", "1,2");
501 OP ("1,0", "0,0", "1,0");
502 OP ("1,0", "0,1", "1,1");
503 OP ("1,0", "1,0", "2,0");
504 OP ("1,0", "1,1", "2,1");
505 OP ("1,1", "0,0", "1,1");
506 OP ("1,1", "0,1", "1,2");
507 OP ("1,1", "1,0", "2,1");
508 OP ("1,1", "1,1", "2,2");
509}
510
511
513template <class T>
514void test_sub_assign (const T*, const char *tname, const char *opname)
515{
516 rw_info (0, 0, __LINE__,
517 "std::valarray<%s>::operator%s (const std::valarray<%1$s>&)",
518 tname, opname);
519
520 std::valarray<T>& (std::valarray<T>::*op)(const std::valarray<T>&) =
521 &std::valarray<T>::operator-=;
522
523 OP ("", "", "");
524
525 OP (" 0", " 0", " 0");
526 OP (" 0", "+1", "-1");
527 OP ("+1", " 0", "+1");
528 OP ("+1", "-1", "+2");
529 OP ("-1", "+1", "-2");
530
531 OP (" 0@12", " 0@12", " 0@12");
532 OP (" 0@23", "+1@23", "-1@23");
533 OP ("+1@34", " 0@34", "+1@34");
534 OP ("+1@45", "-1@45", "+2@45");
535 OP ("-1@56", "+1@56", "-2@56");
536}
537
538
540template <class T>
541void test_xor_assign (const T*, const char *tname, const char *opname)
542{
543 rw_info (0, 0, __LINE__,
544 "std::valarray<%s>::operator%s (const std::valarray<%1$s>&)",
545 tname, opname);
546
547 std::valarray<T>& (std::valarray<T>::*op)(const std::valarray<T>&) =
548 &std::valarray<T>::operator^=;
549
550 OP ("", "", "");
551
552 OP ("0", "0", "0");
553 OP ("0", "1", "1");
554 OP ("1", "0", "1");
555 OP ("1", "1", "0");
556 OP ("3", "0", "3");
557 OP ("3", "1", "2");
558 OP ("3", "2", "1");
559 OP ("3", "3", "0");
560
561 OP ("0@10", "0@10", "0@10");
562 OP ("0@11", "1@11", "1@11");
563 OP ("1@12", "0@12", "1@12");
564 OP ("1@13", "1@13", "0@13");
565 OP ("3@14", "0@14", "3@14");
566 OP ("3@15", "1@15", "2@15");
567 OP ("3@16", "2@16", "1@16");
568 OP ("3@17", "3@17", "0@17");
569}
570
571CANNOT_TEST (float, xor_assign);
572CANNOT_TEST (double, xor_assign);
573CANNOT_TEST (UserClass, xor_assign);
574
575
577template <class T>
578void test_and_assign (const T*, const char *tname, const char *opname)
579{
580 rw_info (0, 0, __LINE__,
581 "std::valarray<%s>::operator%s (const std::valarray<%1$s>&)",
582 tname, opname);
583
584 std::valarray<T>& (std::valarray<T>::*op)(const std::valarray<T>&) =
585 &std::valarray<T>::operator&=;
586
587 OP ("", "", "");
588
589 OP ("0", "0", "0");
590 OP ("0", "1", "0");
591 OP ("1", "0", "0");
592 OP ("1", "1", "1");
593 OP ("3", "0", "0");
594 OP ("3", "1", "1");
595 OP ("3", "2", "2");
596 OP ("3", "3", "3");
597
598 OP ("0@10", "0@10", "0@10");
599 OP ("0@11", "1@11", "0@11");
600 OP ("1@12", "0@12", "0@12");
601 OP ("1@13", "1@13", "1@13");
602 OP ("3@14", "0@14", "0@14");
603 OP ("3@15", "1@15", "1@15");
604 OP ("3@16", "2@16", "2@16");
605 OP ("3@17", "3@17", "3@17");
606}
607
608CANNOT_TEST (float, and_assign);
609CANNOT_TEST (double, and_assign);
610CANNOT_TEST (UserClass, and_assign);
611
612
614template <class T>
615void test_or_assign (const T*, const char *tname, const char *opname)
616{
617 rw_info (0, 0, __LINE__,
618 "std::valarray<%s>::operator%s (const std::valarray<%1$s>&)",
619 tname, opname);
620
621 std::valarray<T>& (std::valarray<T>::*op)(const std::valarray<T>&) =
622 &std::valarray<T>::operator|=;
623
624 OP ("", "", "");
625
626 OP ("0", "0", "0");
627 OP ("0", "1", "1");
628 OP ("1", "0", "1");
629 OP ("1", "1", "1");
630 OP ("3", "0", "3");
631 OP ("3", "1", "3");
632 OP ("3", "2", "3");
633 OP ("3", "3", "3");
634
635 OP ("0@10", "0@10", "0@10");
636 OP ("0@11", "1@11", "1@11");
637 OP ("1@12", "0@12", "1@12");
638 OP ("1@13", "1@13", "1@13");
639 OP ("3@14", "0@14", "3@14");
640 OP ("3@15", "1@15", "3@15");
641 OP ("3@16", "2@16", "3@16");
642 OP ("3@17", "3@17", "3@17");
643}
644
645CANNOT_TEST (float, or_assign);
646CANNOT_TEST (double, or_assign);
648
649
651template <class T>
652void test_shl_assign (const T*, const char *tname, const char *opname)
653{
654 rw_info (0, 0, __LINE__,
655 "std::valarray<%s>::operator%s (const std::valarray<%1$s>&)",
656 tname, opname);
657
658 std::valarray<T>& (std::valarray<T>::*op)(const std::valarray<T>&) =
659 &std::valarray<T>::operator<<=;
660
661 OP ("", "", "");
662
663 OP ("0", "0", "0");
664 OP ("0", "1", "0");
665 OP ("1", "0", "1");
666 OP ("1", "1", "2");
667 OP ("3", "0", "3");
668 OP ("3", "1", "6");
669 OP ("3", "2", "12");
670 OP ("3", "3", "24");
671
672 OP ("0@10", "0@10", "0@10");
673 OP ("0@11", "1@11", "0@11");
674 OP ("1@12", "0@12", "1@12");
675 OP ("1@13", "1@13", "2@13");
676 OP ("3@14", "0@14", "3@14");
677 OP ("3@15", "1@15", "6@15");
678 OP ("3@16", "2@16", "12@16");
679 OP ("3@17", "3@17", "24@17");
680}
681
682CANNOT_TEST (float, shl_assign);
683CANNOT_TEST (double, shl_assign);
684CANNOT_TEST (UserClass, shl_assign);
685
686
688template <class T>
689void test_shr_assign (const T*, const char *tname, const char *opname)
690{
691 rw_info (0, 0, __LINE__,
692 "std::valarray<%s>::operator%s (const std::valarray<%1$s>&)",
693 tname, opname);
694
695 std::valarray<T>& (std::valarray<T>::*op)(const std::valarray<T>&) =
696 &std::valarray<T>::operator>>=;
697
698 OP ("", "", "");
699
700 OP ("0", "0", "0");
701 OP ("0", "1", "0");
702 OP ("1", "0", "1");
703 OP ("2", "1", "1");
704 OP ("3", "0", "3");
705 OP ("6", "1", "3");
706 OP ("12", "2", "3");
707 OP ("24", "3", "3");
708
709 OP ("0@21", "0@21", "0@21");
710 OP ("0@21", "1@21", "0@21");
711 OP ("1@21", "0@21", "1@21");
712 OP ("2@21", "1@21", "1@21");
713 OP ("3@21", "0@21", "3@21");
714 OP ("6@21", "1@21", "3@21");
715 OP ("12@21", "2@21", "3@21");
716 OP ("24@21", "3@21", "3@21");
717}
718
719CANNOT_TEST (float, shr_assign);
720CANNOT_TEST (double, shr_assign);
721CANNOT_TEST (UserClass, shr_assign);
722
723
725enum {
738
739static int opt_assign [n_assign_ops];
740
741
742template <class T>
743void test_op_assign (const T*, const char *tname)
744{
745 const std::size_t nassigns = sizeof opt_assign / sizeof *opt_assign;
746 for (std::size_t i = 0; i != nassigns; ++i) {
747 if (0 < opt_assign [i]) {
748 for (std::size_t j = 0; j != nassigns; ++j) {
749 if (0 == opt_assign [j])
750 opt_assign [j] = -1;
751 }
752 break;
753 }
754 }
755
756 if (rw_note (0 <= opt_assign [inx_mul_assign], 0, __LINE__,
757 "tests of operator*= disabled"))
758 test_mul_assign ((const T*)0, tname, "*=");
759
760 if (rw_note (0 <= opt_assign [inx_div_assign], 0, __LINE__,
761 "tests of operator/= disabled"))
762 test_div_assign ((const T*)0, tname, "/=");
763
764 if (rw_note (0 <= opt_assign [inx_mod_assign], 0, __LINE__,
765 "tests of operator%= disabled"))
766 test_mod_assign ((const T*)0, tname, "%=");
767
768 if (rw_note (0 <= opt_assign [inx_add_assign], 0, __LINE__,
769 "tests of operator+= disabled"))
770 test_add_assign ((const T*)0, tname, "+=");
771
772 if (rw_note (0 <= opt_assign [inx_sub_assign], 0, __LINE__,
773 "tests of operator-= disabled"))
774 test_sub_assign ((const T*)0, tname, "-=");
775
776 if (rw_note (0 <= opt_assign [inx_xor_assign], 0, __LINE__,
777 "tests of operator^= disabled"))
778 test_xor_assign ((const T*)0, tname, "^=");
779
780 if (rw_note (0 <= opt_assign [inx_and_assign], 0, __LINE__,
781 "tests of operator&= disabled"))
782 test_and_assign ((const T*)0, tname, "&=");
783
784 if (rw_note (0 <= opt_assign [inx_or_assign], 0, __LINE__,
785 "tests of operator|= disabled"))
786 test_or_assign ((const T*)0, tname, "|=");
787
788 if (rw_note (0 <= opt_assign [inx_shl_assign], 0, __LINE__,
789 "tests of operator<<= disabled"))
790 test_shr_assign ((const T*)0, tname, "<<=");
791
792 if (rw_note (0 <= opt_assign [inx_shr_assign], 0, __LINE__,
793 "tests of operator>>= disabled"))
794 test_shr_assign ((const T*)0, tname, ">>=");
795}
796
797
799static int
800run_test (int, char**)
801{
802#undef TEST
803#define TEST(T) test_op_assign ((const T*)0, #T)
804
805 TEST (int);
806 TEST (double);
807
808#if 0x05000000 > _RWSTD_VER
809
810 // test fails to compile with stdcxx 4.x and prior due to
811 // STDCXX-512: http://issues.apache.org/jira/browse/STDCXX-512
812 rw_warn (0, 0, __LINE__,
813 "test of UserClass disabled in stdcxx 4.2.0 and prior "
814 "due to STDCXX-512");
815
816#else // stdcxx >= 4.2.1
817
818 TEST (UserClass);
819
820#endif // stdcxx version
821
822 return 0;
823}
824
825
827int main (int argc, char *argv[])
828{
829 // FIXME: add command line options to enable/disable each operator
830 return rw_test (argc, argv, __FILE__,
831 "valarray.cassign",
832 0 /* no comment */,
833 run_test,
834 "|-times~ "
835 "|-divide~ "
836 "|-modulo~ "
837 "|-plus~ "
838 "|-minus~ "
839 "|-xor~ "
840 "|-and~ "
841 "|-or~ "
842 "|-shift_left~ "
843 "|-shift_right~",
844 opt_assign + inx_mul_assign,
845 opt_assign + inx_div_assign,
846 opt_assign + inx_mod_assign,
847 opt_assign + inx_add_assign,
848 opt_assign + inx_sub_assign,
849 opt_assign + inx_xor_assign,
850 opt_assign + inx_and_assign,
851 opt_assign + inx_or_assign,
852 opt_assign + inx_shl_assign,
853 opt_assign + inx_shr_assign,
854 (void*)0 /* sentinel */);
855}
#define i
Definition 17.names.cpp:126
#define T
Definition 17.names.cpp:163
#define e
Definition 17.names.cpp:118
#define line
Definition 17.names.cpp:490
#define res
Definition 17.names.cpp:531
#define a
Definition 17.names.cpp:109
#define buf
Definition 17.names.cpp:452
#define j
Definition 17.names.cpp:127
#define tmp
Definition 17.names.cpp:553
#define s
#define val
Definition 17.names.cpp:570
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
T value(const T &val)
void test_or_assign(const T *, const char *tname, const char *opname)
const std::size_t * count(const T *)
void test_and_assign(const T *, const char *tname, const char *opname)
#define CANNOT_TEST(T, name)
T * make_array(const T *, const char *s, std::size_t *psize)
void test_op_assign(const T *, std::valarray< T > &(std::valarray< T >::*op_assign)(const std::valarray< T > &), const char *tname, const char *opname, int line, const char *lhs_str, const char *rhs_str, const char *res_str)
void test_xor_assign(const T *, const char *tname, const char *opname)
void test_mul_assign(const T *, const char *tname, const char *opname)
#define OP(lhs, rhs, res)
void delete_array(const T *array, std::size_t)
void test_mod_assign(const T *, const char *tname, const char *opname)
#define TEST(T)
void test_shl_assign(const T *, const char *tname, const char *opname)
void test_div_assign(const T *, const char *tname, const char *opname)
void test_shr_assign(const T *, const char *tname, const char *opname)
void test_add_assign(const T *, const char *tname, const char *opname)
void test_sub_assign(const T *, const char *tname, const char *opname)
const int end
#define main
#define _RWSTD_STATIC_CAST(T, x)
Definition _defs.h:534
#define _RWSTD_CONST_CAST(T, x)
Definition _defs.h:536
A TOML array.
Definition array.hpp:258
Definition json.h:5363
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
_TEST_EXPORT int rw_info(int, const char *, int, const char *,...)
Definition driver.cpp:1681
_TEST_EXPORT int rw_note(int, const char *, int, const char *,...)
Definition driver.cpp:1664
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
Definition driver.cpp:1630
_TEST_EXPORT int rw_warn(int, const char *, int, const char *,...)
Definition driver.cpp:1647
_TEST_EXPORT int rw_asnprintf(char **pbuf, _RWSTD_SIZE_T *pbufsize, const char *fmt,...)
#define RW_ASSERT(expr)
UserData data_
Definition rw_value.h:79
static _RWSTD_SIZE_T count_
Definition rw_value.h:120
int val_
Definition rw_value.h:39