1 // Copyright (C) 2005-2018 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // 20.3.6 Binders
19
20 // { dg-do compile }
21
22 #include <functional>
23 using namespace std;
24
25 struct s
26 {
f_void_int_consts27 void f_void_int_const(int) const {}
f_void_ints28 void f_void_int(int) {}
f_int_int_consts29 int f_int_int_const(int) const { return 1; }
f_int_ints30 int f_int_int(int) {return 1; }
f_void_void_consts31 void f_void_void_const() const {}
f_void_voids32 void f_void_void() {}
f_int_void_consts33 int f_int_void_const() const { return 1; }
f_int_voids34 int f_int_void() { return 1; }
35 };
36
test01(s & a)37 void test01(s& a)
38 {
39 mem_fun_t<void, s> p1(&s::f_void_void);
40 mem_fun_t<int, s> p2(&s::f_int_void);
41 p1(&a);
42 p2(&a);
43 mem_fun1_t<void, s, int> q1(&s::f_void_int);
44 mem_fun1_t<int, s, int> q2(&s::f_int_int);
45 q1(&a,0);
46 q2(&a,0);
47
48 (mem_fun(&s::f_void_void))(&a);
49 (mem_fun(&s::f_void_int))(&a,0);
50 (mem_fun(&s::f_int_void))(&a);
51 (mem_fun(&s::f_int_int))(&a,0);
52
53 mem_fun_ref_t<void, s> ref1(&s::f_void_void);
54 mem_fun_ref_t<int, s> ref2(&s::f_int_void);
55
56 ref1(a);
57 ref2(a);
58
59 mem_fun1_ref_t<void, s, int> ref3(&s::f_void_int);
60 mem_fun1_ref_t<int, s, int> ref4(&s::f_int_int);
61
62 ref3(a,0);
63 ref4(a,0);
64
65 (mem_fun_ref(&s::f_void_void))(a);
66 (mem_fun_ref(&s::f_void_int))(a, 0);
67 (mem_fun_ref(&s::f_int_void))(a);
68 (mem_fun_ref(&s::f_int_int))(a, 0);
69 }
70
test02(const s & a)71 void test02(const s& a)
72 {
73 const_mem_fun_t<void, s> p1(&s::f_void_void_const);
74 const_mem_fun_t<int, s> p2(&s::f_int_void_const);
75 p1(&a);
76 p2(&a);
77 const_mem_fun1_t<void, s, int> q1(&s::f_void_int_const);
78 const_mem_fun1_t<int, s, int> q2(&s::f_int_int_const);
79 q1(&a,0);
80 q2(&a,0);
81
82 (mem_fun(&s::f_void_void_const))(&a);
83 (mem_fun(&s::f_void_int_const))(&a, 0);
84 (mem_fun(&s::f_int_void_const))(&a);
85 (mem_fun(&s::f_int_int_const))(&a, 0);
86
87 const_mem_fun_ref_t<void, s> ref1(&s::f_void_void_const);
88 const_mem_fun_ref_t<int, s> ref2(&s::f_int_void_const);
89
90 ref1(a);
91 ref2(a);
92
93 const_mem_fun1_ref_t<void, s, int> ref3(&s::f_void_int_const);
94 const_mem_fun1_ref_t<int, s, int> ref4(&s::f_int_int_const);
95
96 ref3(a,0);
97 ref4(a,0);
98
99 (mem_fun_ref(&s::f_void_void_const))(a);
100 (mem_fun_ref(&s::f_void_int_const))(a, 0);
101 (mem_fun_ref(&s::f_int_void_const))(a);
102 (mem_fun_ref(&s::f_int_int_const))(a, 0);
103 }
104