Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
20.function.objects.cpp
Go to the documentation of this file.
1
29#include <functional>
30
31#include <rw_driver.h>
32
33#if defined (__HP_aCC) && _RWSTD_HP_aCC_MAJOR < 6
34
35// working around an HP aCC bug (see PR #25378)
36# include <string>
37
38// working around an HP aCC bug (see PR #24417)
39_USING (namespace std);
40
41#endif // HP aCC < 6
42
43
45#ifdef _MSC_VER
46 // shut up the idiotic MSVC 6.0 warning C4099:
47 // type name first seen using 'struct' now seen using 'class'
48# pragma warning (disable: 4099)
49
50 // another bogus warning C4700:
51 // local variable used without having been initialized
52# pragma warning (disable: 4700)
53
54# if _MSC_VER <= 1300
55 // work around a bug where the compiler thinks that what's a struct
56 // is really a class with all private members (PR #23795)
57# define class struct
58# endif
59#endif
60
61
62#ifndef _RWSTD_EXPLICIT_INSTANTIATION
63
64 // explicitly instantiate
65
66# if !defined (_RWSTD_NO_NAMESPACE) && !defined (_RWSTD_NO_HONOR_STD) \
67 && (!defined (_COMPILER_VERSION) || _COMPILER_VERSION > 730) \
68 && (!defined (__EDG_VERSION__) || __EDG_VERSION__ > 244)
69
70 // work around an EDG front end bug (see, for example, PR #25292)
71
72 // verify that names are declared [only] in namespace std
73
74# define TEST_CLASS_DEF(name, Tparam) \
75 template class std::name Tparam; \
76 void name (void *name)
77# define TEST_CLASS_DEF_2(name, Tparam1, Tparam2) \
78 template class std::name Tparam1, Tparam2; \
79 void name (void *name)
80# define TEST_CLASS_DEF_3(name, Tparam1, Tparam2, Tparam3) \
81 template class std::name Tparam1, Tparam2, Tparam3; \
82 void name (void *name)
83
84# else // if defined (_RWSTD_NO_NAMESPACE) || defined (_RWSTD_NO_HONOR_STD)
85
86 // verify that names do not collide with function argument names
87
88# define TEST_CLASS_DEF(name, Tparam) \
89 template class std::name Tparam; \
90 void foo (void *name)
91# define TEST_CLASS_DEF_2(name, Tparam1, Tparam2) \
92 template class std::name Tparam1, Tparam2; \
93 void foo (void *name)
94# define TEST_CLASS_DEF_3(name, Tparam1, Tparam2, Tparam3) \
95 template class std::name Tparam1, Tparam2, Tparam3; \
96 void foo (void *name)
97# endif // !_RWSTD_NO_NAMESPACE && !_RWSTD_NO_HONOR_STD
98
99# if defined __GNUG__ && __GNUG__ < 3 && __GNU_MINOR__ < 96
100
101 // working around a bug in g++ 2.95.2 (PR #23151)
102# define TEST_FUNCTION_DEF(decl) \
103 _RWSTD_NAMESPACE (std) { \
104 template decl; \
105 } /* namespace std */ \
106 typedef void unused_typedef
107# else
108# define TEST_FUNCTION_DEF(decl) template decl
109# endif
110
111#else // if defined (_RWSTD_EXPLICIT_INSTANTIATION)
112
113 // classes will implicitly instantiated below
114
115# if !defined (_RWSTD_NO_NAMESPACE) && !defined (_RWSTD_NO_HONOR_STD)
116
117 // verify that names are declared [only[ in namespace std
118
119# define TEST_CLASS_DEF(name, ignore) void name (void *name)
120# define TEST_CLASS_DEF_2(name, ign1, ign2) void name (void *name)
121# define TEST_CLASS_DEF_3(name, ign1, ign2, ign3) void name (void *name)
122
123# else // if defined (_RWSTD_NO_NAMESPACE) || defined (_RWSTD_NO_HONOR_STD)
124
125# define TEST_CLASS_DEF(name, ignore) void foo (void *name)
126# define TEST_CLASS_DEF_2(name, ign1, ign2) void foo (void *name)
127# define TEST_CLASS_DEF_3(name, ign1, ign2, ign3) void foo (void *name)
128
129# endif // !_RWSTD_NO_NAMESPACE && !_RWSTD_NO_HONOR_STD
130
131# define TEST_FUNCTION_DEF(ignore) void unused_typedef
132
133#endif // _RWSTD_EXPLICIT_INSTANTIATION
134
135
136TEST_CLASS_DEF_2 (unary_function, <int, int>);
137TEST_CLASS_DEF_3 (binary_function, <int, int, int>);
138
141TEST_CLASS_DEF (multiplies, <int>);
142TEST_CLASS_DEF (divides, <int>);
143TEST_CLASS_DEF (modulus, <int>);
144TEST_CLASS_DEF (negate, <int>);
145
146TEST_CLASS_DEF (equal_to, <int>);
147TEST_CLASS_DEF (not_equal_to, <int>);
148TEST_CLASS_DEF (greater, <int>);
149TEST_CLASS_DEF (less, <int>);
150TEST_CLASS_DEF (greater_equal, <int>);
151TEST_CLASS_DEF (less_equal, <int>);
152
153TEST_CLASS_DEF (logical_and, <int>);
154TEST_CLASS_DEF (logical_or, <int>);
155TEST_CLASS_DEF (logical_not, <int>);
156
157TEST_CLASS_DEF (unary_negate, <std::negate<int> >);
158
160 std::unary_negate<std::negate<int> >
161 std::not1 (const std::negate<int>&));
162
163TEST_CLASS_DEF (binary_negate, <std::equal_to<int> >);
164
166 std::binary_negate<std::equal_to<int> >
167 std::not2 (const std::equal_to<int>&));
168
169TEST_CLASS_DEF (binder1st, <std::plus<int> >);
170
172 std::binder1st<std::plus<int> >
173 std::bind1st (const std::plus<int>&, const int&));
174
175TEST_CLASS_DEF (binder2nd , <std::plus<int> >);
176
178 std::binder2nd<std::plus<int> >
179 std::bind2nd (const std::plus<int>&, const int&));
180
181
183// exercise 20.3.1 [lib.base]
184static void
185test_base ()
186{
187 rw_info (0, 0, __LINE__, "[lib.base]");
188
189 // verify that member types really are of the correct types
190 std::unary_function<int, void>::argument_type *argument = (int*)0;
191 std::unary_function<int, void>::result_type *result = (void*)0;
192
193 std::binary_function<int, char, void>::first_argument_type *a1 = (int*)0;
194 std::binary_function<int, char, void>::second_argument_type *a2 = (char*)0;
195 std::binary_function<int, char, void>::result_type *res = (void*)0;
196
197 _RWSTD_UNUSED (argument);
202}
203
204
205#define TEST_UNARY_OP(fun, op, x) do { \
206 rw_info (0, 0, __LINE__, "std::" #fun); \
207 N::fun f CTOR_ARG_LIST; \
208 /* verify that fun is copy constructible and assignable */ \
209 const N::fun f_cpy1 (f); \
210 /* const to verify copy ctor const correctness */ \
211 const N::fun f_cpy2 = f; \
212 /* verify that fun publicly derives from unary_function */ \
213 const std::unary_function<N::fun::argument_type, \
214 N::fun::result_type> *pf = &f; \
215 _RWSTD_UNUSED (pf); \
216 /* verify member types and signature of operator () */ \
217 typedef N::fun fun_t; /* in case fun contains commas */ \
218 N::fun::result_type (N::fun::*pfun) \
219 UNARY_OP_ARG_LIST (fun_t) const = &N::fun::operator(); \
220 _RWSTD_UNUSED (pfun); \
221 /* exercise operator() */ \
222 rw_assert (f.operator() (x) == (op x), 0, __LINE__, \
223 #fun "().operator()(%i) == %i, got %i", \
224 x, (op x), f.operator()(x)); \
225 /* exercise operator() of the two copies */ \
226 rw_assert (f_cpy1.operator() (x) == (op x), 0, __LINE__, \
227 #fun "::" #fun "(const " #fun "&)"); \
228 rw_assert (f_cpy2.operator() (x) == (op x), 0, __LINE__, \
229 #fun "::operator=" #fun "(const " #fun "&)"); \
230 } while (0)
231
232#define TEST_BINARY_OP(fun, op, x, y) do { \
233 rw_info (0, 0, __LINE__, "std::" #fun); \
234 N::fun f CTOR_ARG_LIST; \
235 /* verify that fun is copy constructible and assignable */ \
236 const N::fun f_cpy1 (f); \
237 /* const to verify copy ctor const correctness */ \
238 const N::fun f_cpy2 = f; \
239 /* verify that fun publicly derives from binary_function */ \
240 const std::binary_function<N::fun::first_argument_type, \
241 N::fun::second_argument_type, \
242 N::fun::result_type> *pf = &f; \
243 _RWSTD_UNUSED (pf); \
244 /* verify member types and signature of operator () */ \
245 typedef N::fun fun_t; /* in case fun contains commas */ \
246 N::fun::result_type (N::fun::*pfun) \
247 BINARY_OP_ARG_LIST (fun_t) const = &N::fun::operator(); \
248 _RWSTD_UNUSED (pfun); \
249 rw_assert (f.operator() (x, y) == (x op y), 0, __LINE__, \
250 #fun "().operator()(%i, %i) == %i, got %i", \
251 x, y, (x op y), f.operator()(x, y)); \
252 /* exercise operator() of the two copies */ \
253 rw_assert (f_cpy1.operator() (x, y) == (x op y), 0, __LINE__, \
254 #fun "::" #fun "(const " #fun "&)"); \
255 rw_assert (f_cpy2.operator() (x, y) == (x op y), 0, __LINE__, \
256 #fun "::operator=" #fun "(const " #fun "&)"); \
257 } while (0)
258
259
260// tested fununctions are in namespace std
261#define N std
262
263// most but not all operator() take arguments by const reference
264#define UNARY_OP_ARG_LIST(fun) (const fun::argument_type&)
265#define BINARY_OP_ARG_LIST(fun) \
266 (const fun::first_argument_type&, const fun::second_argument_type&)
267
268// use default ctor in tests below
269#define CTOR_ARG_LIST
270
271// exercise 20.3.2 [lib.arithmetic.operations]
272static void
273test_arithmetic_operations ()
274{
275 rw_info (0, 0, __LINE__, "[lib.arithmetic.operations]");
276
277 // 20.3.2, p2
278 TEST_BINARY_OP (plus<int>, +, 1, 2);
279
280 // 20.3.2, p3
281 TEST_BINARY_OP (minus<int>, -, 3, 2);
282
283 // 20.3.2, p4
284 TEST_BINARY_OP (multiplies<int>, *, 2, 3);
285
286 // 20.3.2, p5
287 TEST_BINARY_OP (divides<int>, /, 6, 3);
288
289 // 20.3.2, p6
290 TEST_BINARY_OP (modulus<int>, %, 7, 3);
291
292 // 20.3.2, p7
293 TEST_UNARY_OP (negate<int>, -, 1);
294
295 // exercise extensions
296
297// tested fununctions are in a private namespace
298#undef N
299#define N _RW
300
301 TEST_UNARY_OP (identity<int>, +, 3);
302 TEST_UNARY_OP (unary_plus<int>, +, 4);
303 TEST_UNARY_OP (bitwise_complement<int>, ~, 5);
304
305 TEST_BINARY_OP (bitwise_and<int>, &, 0x0f, 0x05);
306 TEST_BINARY_OP (bitwise_or<int>, |, 0x0f, 0xf0);
307 TEST_BINARY_OP (exclusive_or<int>, ^, 0x0f, 0xf1);
308
309 TEST_BINARY_OP (shift_left<int>, <<, 3, 3);
310 TEST_BINARY_OP (shift_right<int>, >>, 15, 3);
311
312// remaining tested fununctions are in namespace std
313#undef N
314#define N std
315}
316
317
319// exercise 20.3.3 [lib.comparisons]
320static void
321test_comparisons ()
322{
323 rw_info (0, 0, __LINE__, "[lib.comparisons]");
324
325 // 20.3.3, p2
326 TEST_BINARY_OP (equal_to<int>, ==, 1, 1);
327 TEST_BINARY_OP (equal_to<double>, ==, 1.0, 2.0);
328
329 // 20.3.3, p3
330 TEST_BINARY_OP (not_equal_to<int>, !=, 1, 1);
331 TEST_BINARY_OP (not_equal_to<double>, !=, 1.0, 2.0);
332
333 // 20.3.3, p4
334 TEST_BINARY_OP (greater<int>, >, 1, 1);
335 TEST_BINARY_OP (greater<double>, >, 2.0, 1.0);
336
337 // 20.3.3, p5
338 TEST_BINARY_OP (less<int>, <, 1, 1);
339 TEST_BINARY_OP (less<double>, <, 1.0, 2.0);
340
341 // 20.3.3, p6
342 TEST_BINARY_OP (greater_equal<int>, >=, 1, 1);
343 TEST_BINARY_OP (greater_equal<double>, >=, 1.0, 2.0);
344
345 // 20.3.3, p7
346 TEST_BINARY_OP (less_equal<int>, <=, 1, 1);
347 TEST_BINARY_OP (less_equal<double>, <=, 2.0, 1.0);
348
349 // 20.3.3, p8
350 // ???
351}
352
353
355// exercise 20.3.4 [lib.logical.operations]
356static void
357test_logical_operations ()
358{
359 rw_info (0, 0, __LINE__, "[lib.logical.operations]");
360
361 // 20.3.4, p2
362 TEST_BINARY_OP (logical_and<int>, &&, 0, 1);
363 TEST_BINARY_OP (logical_and<double>, &&, 1.0, 2.0);
364
365 // 20.3.4, p3
366 TEST_BINARY_OP (logical_or<char>, ||, '\0', '\0');
367 TEST_BINARY_OP (logical_or<int>, ||, 0, 1);
368 TEST_BINARY_OP (logical_or<double>, ||, 1.0, 2.0);
369
370 // 20.3.4, p4
371 TEST_UNARY_OP (logical_not<int>, !, 0);
372 TEST_UNARY_OP (logical_not<double>, !, 2.0);
373}
374
375
376// helpers to verify that each class' ctor is explicit
377// not defined since they must not be referenced if test is successful
378void is_explicit (const std::unary_negate<std::logical_not<int> >&);
379void is_explicit (const std::binary_negate<std::equal_to<int> >&);
380void is_explicit (const std::pointer_to_unary_function<int, int>&);
381void is_explicit (const std::pointer_to_binary_function<int, int, int>&);
382
384{
385 // NOT explicit
386 has_implicit_ctor (const std::logical_not<int>&) { }
387 has_implicit_ctor (const std::equal_to<int>&) { }
388
389 has_implicit_ctor (int (*)(int)) { }
390 has_implicit_ctor (int (*)(int, int)) { }
391};
392
393
396
397
398// exercise 20.3.5 [lib.negators]
399static void
400test_negators ()
401{
402 rw_info (0, 0, __LINE__, "[lib.negators]");
403
404 // verify that std::unary_negate<>() and std::binary_negate<>()
405 // ctors are declared explicit
406 is_explicit (std::logical_not<int>());
407
408// use std::negate<> as an argument in negator ctors
409#undef CTOR_ARG_LIST
410#define CTOR_ARG_LIST \
411 = std::unary_negate<std::logical_not<int> > (std::logical_not<int> ())
412
413 // 20.3.5, p2
414 TEST_UNARY_OP (unary_negate<std::logical_not<int> >, !!, 0);
415 TEST_UNARY_OP (unary_negate<std::logical_not<int> >, !!, 1);
416
417// exercise the convenience function template std::not1()
418#undef CTOR_ARG_LIST
419#define CTOR_ARG_LIST = std::not1 (std::logical_not<char> ())
420
421 // 20.3.5, p3
422 TEST_UNARY_OP (unary_negate<std::logical_not<char> >, !!, '\0');
423 TEST_UNARY_OP (unary_negate<std::logical_not<char> >, !!, '1');
424
425// use std::equal_to<> as an argument in negator ctors
426#undef CTOR_ARG_LIST
427#define CTOR_ARG_LIST \
428 = std::binary_negate<std::equal_to<double> > (std::equal_to<double> ())
429
430 // 20.3.5, p4
431 TEST_BINARY_OP (binary_negate<std::equal_to<double> >, !=, 0.0, 1.0);
432 TEST_BINARY_OP (binary_negate<std::equal_to<double> >, !=, 1.0, 2.0);
433
434// use std::not_equal_to<> as an argument in negator ctors
435#undef CTOR_ARG_LIST
436#define CTOR_ARG_LIST \
437 = std::binary_negate<std::not_equal_to<int> > (std::not_equal_to<int> ())
438
439 TEST_BINARY_OP (binary_negate<std::not_equal_to<int> >, ==, 0, 1);
440 TEST_BINARY_OP (binary_negate<std::not_equal_to<int> >, ==, 1, 2);
441
442// exercise the convenience function template std::not2()
443#undef CTOR_ARG_LIST
444#define CTOR_ARG_LIST = std::not2 (std::equal_to<int> ())
445
446 // 20.3.5, p5
447 TEST_BINARY_OP (binary_negate<std::equal_to<int> >, !=, 2, 2);
448 TEST_BINARY_OP (binary_negate<std::equal_to<int> >, !=, 3, 4);
449}
450
451
453// exercise 20.3.6 [lib.binders]
454static void
455test_binders ()
456{
457 rw_info (0, 0, __LINE__, "[lib.binders]");
458
459 // make sure the protected names `op' and `value' are accessible
460 struct binder1st_derivative: std::binder1st<std::minus<int> > {
461
462 binder1st_derivative ()
463 : std::binder1st<std::minus<int> >(std::minus<int> (), 0) {
464
465 // test protected access
466 rw_assert (0 == op (value, value), 0, __LINE__,
467 "binder1st<>::op");
468 rw_assert (0 == operator()(value), 0, __LINE__,
469 "binder1st<>::operator()");
470
471 value = 7;
472 rw_assert (-7 == op (0, value), 0, __LINE__,
473 "binder1st<>::value");
474 rw_assert (7 == operator()(0), 0, __LINE__,
475 "binder1st<>::operator()");
476 }
477 } b1st;
478
479 _RWSTD_UNUSED (b1st);
480
481 // make sure the protected names `op' and `value' are accessible
482 struct binder2nd_derivative: std::binder2nd<std::minus<int> > {
483 binder2nd_derivative ()
484 : std::binder2nd<std::minus<int> >(std::minus<int> (), 0) {
485
486 // test protected access
487 rw_assert (0 == op (value, value), 0, __LINE__,
488 "binder2nd<>::op");
489 rw_assert (0 == operator()(value), 0, __LINE__,
490 "binder2nd<>::operator()");
491
492 value = 7;
493 rw_assert (-7 == op (0, value), 0, __LINE__,
494 "binder2nd<>::value");
495 rw_assert (-7 == operator()(0), 0, __LINE__,
496 "binder2nd<>::operator()");
497 }
498 } b2nd;
499
500 _RWSTD_UNUSED (b2nd);
501
502#undef CTOR_ARG_LIST
503
504#if defined __GNUG__ && __GNUG__ < 3 && __GNU_MINOR__ < 96
505 // broken out of the macro definition to work around
506 // a bug in g++ 2.95.2 parser
507 std::minus<int> obj_minus;
508
509 // use std::negate<> as an argument in negator ctors
510# define CTOR_ARG_LIST (obj_minus, 1)
511#else
512# define CTOR_ARG_LIST (std::minus<int>(), 1)
513#endif
514
515 // 20.3.6.1, p1 and p2
516 TEST_UNARY_OP (binder1st<std::minus<int> >, 1 -, 0);
517 TEST_UNARY_OP (binder1st<std::minus<int> >, 1 -, 1);
518
519 // 20.3.6.3, p1 and p2
520 TEST_UNARY_OP (binder2nd<std::minus<int> >, -1 +, 0);
521 TEST_UNARY_OP (binder2nd<std::minus<int> >, 1 -, 1);
522
523// exercise the convenience function template std::bind1st<>()
524#undef CTOR_ARG_LIST
525#define CTOR_ARG_LIST = std::bind1st (std::divides<int>(), 6)
526
527 // 20.3.6.2, p1
528 TEST_UNARY_OP (binder1st<std::divides<int> >, 6 /, 3);
529 TEST_UNARY_OP (binder1st<std::divides<int> >, 6 /, 2);
530
531// exercise the convenience function template std::bind2nd<>()
532#undef CTOR_ARG_LIST
533#define CTOR_ARG_LIST = std::bind2nd (std::plus<int>(), -2)
534
535 // 20.3.6.4, p1
536 TEST_UNARY_OP (binder2nd<std::plus<int> >, -2 +, 0);
537 TEST_UNARY_OP (binder2nd<std::plus<int> >, -2 +, 1);
538}
539
540
542// helpers to exercise pointer to function adapters
543int square (int i) { return i * i; }
544int shift (int i, int n) { return i << n; }
545
546// exercise 20.3.7 [lib.function.pointer.adaptors]
547static void
548test_function_pointer_adaptors ()
549{
550 rw_info (0, 0, __LINE__, "[lib.function.pointer.adaptors]");
551
552 // verify that the pointer to function adapters' ctors are explicit
553 is_explicit ((int (*)(int))0);
554 is_explicit ((int (*)(int, int))0);
555
556// initialize pointer_to_unary_function with the address of square
557#undef CTOR_ARG_LIST
558#define CTOR_ARG_LIST (&::square)
559
560// operator() takes a value (as opposed to const reference)
561#undef UNARY_OP_ARG_LIST
562#define UNARY_OP_ARG_LIST(fun) (fun::argument_type)
563
564#define pointer_to_unary_function_int pointer_to_unary_function<int, int>
565
566 // 20.3.7, p2
568
569// exercise the convenience function template ptr_fun()
570#undef CTOR_ARG_LIST
571#define CTOR_ARG_LIST = std::ptr_fun (&::square)
572
573 // 20.3.7, p3
575
576// initialize pointer_to_binary_function with the address of shift
577#undef CTOR_ARG_LIST
578#define CTOR_ARG_LIST (&::shift)
579
580// operator() takes values (as opposed to const references)
581#undef BINARY_OP_ARG_LIST
582#define BINARY_OP_ARG_LIST(fun) \
583 (fun::first_argument_type, fun::second_argument_type)
584
585#define pointer_to_binary_function_int pointer_to_binary_function<int, int, int>
586
587 // 20.3.7, p4
589
590// exercise the convenience function template ptr_fun()
591#undef CTOR_ARG_LIST
592#define CTOR_ARG_LIST = std::ptr_fun (&::shift)
593
594 // 20.3.7, p5
596}
597
598
601{
602 int i_;
603
604 // for convenience
605 operator int () const { return i_; }
606
607 // non-const members
608 int square () { return i_ * i_; }
609 int div (short n) { return i_ / n; }
610
611 // const versions of the above members
612 int const_square () const { return i_ * i_; }
613 int const_div (short n) const { return i_ / n; }
614};
615
616
617// helper to verify that each class' ctor is explicit
618// not defined since they must not be referenced if test is successful
619void is_explicit (const std::mem_fun_t<int, Integer>&);
620
622{
623 // NOT explicit
626
628 has_implicit_ctor_from_member (int (Integer::*)(short) const) { }
629};
630
632
633
634// exercise 20.3.8 [lib.member.pointer.adaptors]
635static void
636test_member_pointer_adaptors ()
637{
638 rw_info (0, 0, __LINE__, "[lib.member.pointer.adaptors]");
639
640 // verify that the pointer to member adapters' ctors are explicit
641 is_explicit ((int (Integer::*)())0);
642 is_explicit ((int (Integer::*)(short))0);
643 is_explicit ((int (Integer::*)() const)0);
644 is_explicit ((int (Integer::*)(short) const)0);
645
646#undef CTOR_ARG_LIST
647#define CTOR_ARG_LIST (&Integer::square)
648
649#define mem_fun_t_Integer_int mem_fun_t<int, Integer>
650
651 Integer int_obj = { 5 };
652
653 // 20.3.8, p2
654 TEST_UNARY_OP (mem_fun_t_Integer_int, 5 * (int)*, &int_obj);
655
656#undef CTOR_ARG_LIST
657#define CTOR_ARG_LIST = std::mem_fun (&Integer::square)
658
659 int_obj.i_ = 7;
660
661 // 20.3.8, p4
662 TEST_UNARY_OP (mem_fun_t_Integer_int, 7 * (int)*, &int_obj);
663
664
665#undef CTOR_ARG_LIST
666#define CTOR_ARG_LIST (&Integer::div)
667
668#define mem_fun1_t_int_Integer_short mem_fun1_t<int, Integer, short>
669
670 // 20.3.8, p3
671 TEST_BINARY_OP (mem_fun1_t_int_Integer_short, ->operator int() /,
672 (&int_obj), 2);
673
674#undef CTOR_ARG_LIST
675#define CTOR_ARG_LIST = std::mem_fun (&Integer::div)
676
677 // 20.3.8, p4
678 TEST_BINARY_OP (mem_fun1_t_int_Integer_short, ->operator int() / ,
679 (&int_obj), -1);
680
681
682#undef CTOR_ARG_LIST
683#define CTOR_ARG_LIST (&Integer::square)
684
685// operator() takes a reference (as opposed to const reference or value)
686#undef UNARY_OP_ARG_LIST
687#define UNARY_OP_ARG_LIST(fun) (fun::argument_type&)
688
689#define mem_fun_ref_t_Integer_int mem_fun_ref_t<int, Integer>
690
691 int_obj.i_ = -9;
692
693 // 20.3.8, p5
694 TEST_UNARY_OP (mem_fun_ref_t_Integer_int, -9 * (int), int_obj);
695
696// exercise the convenience function template mem_fun_ref()
697#undef CTOR_ARG_LIST
698#define CTOR_ARG_LIST = std::mem_fun_ref (&Integer::square)
699
700 // 20.3.8, p7
701 TEST_UNARY_OP (mem_fun_ref_t_Integer_int, -9 * (int), int_obj);
702
703#undef CTOR_ARG_LIST
704#define CTOR_ARG_LIST (&Integer::div)
705
706// operator() takes a reference and a value
707#undef BINARY_OP_ARG_LIST
708#define BINARY_OP_ARG_LIST(fun) \
709 (fun::first_argument_type&, fun::second_argument_type)
710
711#define mem_fun1_ref_t_int_Integer_short mem_fun1_ref_t<int, Integer, short>
712
713 // 20.3.8, p6
715 int_obj, 3);
716
717// exercise the convenience function template mem_fun_ref()
718#undef CTOR_ARG_LIST
719#define CTOR_ARG_LIST = std::mem_fun_ref (&Integer::div)
720
721 // 20.3.8, p7
723 int_obj, 3);
724
725
727#undef CTOR_ARG_LIST
728#define CTOR_ARG_LIST (&Integer::const_square)
729
730// operator() takes a const reference (as opposed to reference or value)
731#undef UNARY_OP_ARG_LIST
732#define UNARY_OP_ARG_LIST(fun) (fun::argument_type)
733
734#define const_mem_fun_t_Integer_int const_mem_fun_t<int, Integer>
735
736 int_obj.i_ = 5;
737
738 // verify const-correctness
739 const Integer &int_cref = int_obj;
740
741 // 20.3.8, p2
742 TEST_UNARY_OP (const_mem_fun_t_Integer_int, 5 * (int)*, &int_cref);
743
744#undef CTOR_ARG_LIST
745#define CTOR_ARG_LIST = std::mem_fun (&Integer::const_square)
746
747 int_obj.i_ = 7;
748
749 // 20.3.8, p4
750 TEST_UNARY_OP (const_mem_fun_t_Integer_int, 7 * (int)*, &int_cref);
751
752
753#undef CTOR_ARG_LIST
754#define CTOR_ARG_LIST (&Integer::const_div)
755
756// operator() takes a const value and a value
757#undef BINARY_OP_ARG_LIST
758#define BINARY_OP_ARG_LIST(fun) \
759 (fun::first_argument_type, fun::second_argument_type)
760
761#define const_mem_fun1_t_int_Integer_short \
762 const_mem_fun1_t<int, Integer, short>
763
764 // 20.3.8, p3
766 (&int_cref), 2);
767
768#undef CTOR_ARG_LIST
769#define CTOR_ARG_LIST = std::mem_fun (&Integer::const_div)
770
771 // 20.3.8, p4
773 (&int_cref), -1);
774
775
776#undef CTOR_ARG_LIST
777#define CTOR_ARG_LIST (&Integer::const_square)
778
779// operator() takes a reference (as opposed to const reference or value)
780#undef UNARY_OP_ARG_LIST
781#define UNARY_OP_ARG_LIST(fun) (const fun::argument_type&)
782
783#define const_mem_fun_ref_t_Integer_int const_mem_fun_ref_t<int, Integer>
784
785 int_obj.i_ = -9;
786
787 // 20.3.8, p5
788 TEST_UNARY_OP (const_mem_fun_ref_t_Integer_int, -9 * (int), int_cref);
789
790// exercise the convenience function template const_mem_fun_ref()
791#undef CTOR_ARG_LIST
792#define CTOR_ARG_LIST = std::mem_fun_ref (&Integer::const_square)
793
794 // 20.3.8, p7
795 TEST_UNARY_OP (const_mem_fun_ref_t_Integer_int, -9 * (int), int_cref);
796
797#undef CTOR_ARG_LIST
798#define CTOR_ARG_LIST (&Integer::const_div)
799
800// operator() takes a const reference and a value
801#undef BINARY_OP_ARG_LIST
802#define BINARY_OP_ARG_LIST(fun) \
803 (const fun::first_argument_type&, fun::second_argument_type)
804
805#define const_mem_fun1_ref_t_int_Integer_short \
806 const_mem_fun1_ref_t<int, Integer, short>
807
808 // 20.3.8, p6
810 int_cref, 3);
811
812// exercise the convenience function template const_mem_fun_ref()
813#undef CTOR_ARG_LIST
814#define CTOR_ARG_LIST = std::mem_fun_ref (&Integer::const_div)
815
816 // 20.3.8, p7
818 int_cref, 3);
819}
820
821
823static int
824run_test (int, char**)
825{
826 // exercise 20.3.1 [lib.base]
827 test_base ();
828
829 // exercise 20.3.2 [lib.arithmetic.operations]
830 test_arithmetic_operations ();
831
832 // exercise 20.3.3 [lib.comparisons]
833 test_comparisons ();
834
835 // exercise 20.3.4 [lib.logical.operations]
836 test_logical_operations ();
837
838 // exercise 20.3.5 [lib.negators]
839 test_negators ();
840
841 // exercise 20.3.6 [lib.binders]
842 test_binders ();
843
844 // exercise 20.3.7 [lib.function.pointer.adaptors]
845 test_function_pointer_adaptors ();
846
847 // exercise 20.3.8 [lib.member.pointer.adaptors]
848 test_member_pointer_adaptors ();
849
850 return 0;
851}
852
853
855int main (int argc, char *argv[])
856{
857 return rw_test (argc, argv, __FILE__,
858 "lib.std.function_objects",
859 0 /* no comment */,
860 run_test,
861 "",
862 (void*)0 /* sentinel */);
863}
#define i
Definition 17.names.cpp:126
#define res
Definition 17.names.cpp:531
#define a2
Definition 17.names.cpp:251
#define a1
Definition 17.names.cpp:225
#define n
Definition 17.names.cpp:130
volatile int result
#define TEST_CLASS_DEF_2(name, Tparam1, Tparam2)
#define pointer_to_unary_function_int
int square(int i)
#define const_mem_fun1_ref_t_int_Integer_short
#define const_mem_fun_ref_t_Integer_int
#define mem_fun_ref_t_Integer_int
#define mem_fun1_t_int_Integer_short
#define TEST_CLASS_DEF(name, Tparam)
#define mem_fun1_ref_t_int_Integer_short
#define TEST_CLASS_DEF_3(name, Tparam1, Tparam2, Tparam3)
#define const_mem_fun_t_Integer_int
#define const_mem_fun1_t_int_Integer_short
void is_explicit(const std::unary_negate< std::logical_not< int > > &)
#define pointer_to_binary_function_int
#define mem_fun_t_Integer_int
int shift(int i, int n)
#define TEST_FUNCTION_DEF(decl)
#define TEST_UNARY_OP(fun, op, x)
#define TEST_BINARY_OP(fun, op, x, y)
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
T value(const T &val)
#define main
#define _RWSTD_UNUSED(arg)
Definition _defs.h:972
#define _USING(name)
Definition _defs.h:568
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_assert(int, const char *, int, const char *,...)
Definition driver.cpp:1630
int const_square() const
int div(short n)
int const_div(short n) const
has_implicit_ctor_from_member(int(Integer::*)())
has_implicit_ctor_from_member(int(Integer::*)() const)
has_implicit_ctor_from_member(int(Integer::*)(short) const)
has_implicit_ctor_from_member(int(Integer::*)(short))
has_implicit_ctor(const std::equal_to< int > &)
has_implicit_ctor(int(*)(int, int))
has_implicit_ctor(const std::logical_not< int > &)