31
|
1 |
|
|
2 |
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
3 |
// mem_ptr_fun_test.cpp
|
|
4 |
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
5 |
// Copyright(c) 2001 Meridian'93
|
|
6 |
// http://www.meridian93.com
|
|
7 |
// mailto:info@meridian93.com
|
|
8 |
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
9 |
|
|
10 |
// STLport regression testsuite component.
|
|
11 |
// To compile as a separate example, please #define MAIN.
|
|
12 |
|
|
13 |
#include <functional>
|
|
14 |
#include <memory>
|
|
15 |
|
|
16 |
#ifdef MAIN
|
|
17 |
#define mem_ptr_fun_test main
|
|
18 |
#endif
|
|
19 |
|
|
20 |
#if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
|
|
21 |
using namespace std;
|
|
22 |
#endif
|
|
23 |
|
|
24 |
#if defined(_STLP_DONT_RETURN_VOID) && (defined(_STLP_NO_MEMBER_TEMPLATE_CLASSES) && defined(_STLP_NO_CLASS_PARTIAL_SPECIALIZATION))
|
|
25 |
# define _STLP_DONT_TEST_RETURN_VOID
|
|
26 |
#endif /*_STLP_DONT_RETURN_VOID*/
|
|
27 |
//else there is no workaround for the return void bug
|
|
28 |
|
|
29 |
struct S1 { } s1;
|
|
30 |
struct S2 { } s2;
|
|
31 |
|
|
32 |
int f1(S1&);
|
|
33 |
int f2(S1&, S2&);
|
|
34 |
int f1c(const S1&);
|
|
35 |
int f2c(const S1&, const S2&);
|
|
36 |
|
|
37 |
void vf1(S1&);
|
|
38 |
void vf2(S1&, S2&);
|
|
39 |
void vf1c(const S1&);
|
|
40 |
void vf2c(const S1&, const S2&);
|
|
41 |
|
|
42 |
class Class {
|
|
43 |
public:
|
|
44 |
int f0();
|
|
45 |
int f1(const S1&);
|
|
46 |
|
|
47 |
void vf0();
|
|
48 |
void vf1(const S1&);
|
|
49 |
|
|
50 |
int f0c() const;
|
|
51 |
int f1c(const S1&) const;
|
|
52 |
|
|
53 |
void vf0c() const;
|
|
54 |
void vf1c(const S1&) const;
|
|
55 |
};
|
|
56 |
|
|
57 |
int mem_ptr_fun_test(int, char**)
|
|
58 |
{
|
|
59 |
Class obj;
|
|
60 |
const Class& objc = obj;
|
|
61 |
|
|
62 |
// ptr_fun
|
|
63 |
|
|
64 |
ptr_fun(f1)(s1);
|
|
65 |
ptr_fun(f2)(s1, s2);
|
|
66 |
|
|
67 |
ptr_fun(f1c)(s1);
|
|
68 |
ptr_fun(f2c)(s1, s2);
|
|
69 |
|
|
70 |
#ifndef _STLP_DONT_TEST_RETURN_VOID
|
|
71 |
ptr_fun(vf1)(s1);
|
|
72 |
ptr_fun(vf2)(s1, s2);
|
|
73 |
|
|
74 |
ptr_fun(vf1c)(s1);
|
|
75 |
ptr_fun(vf2c)(s1, s2);
|
|
76 |
#endif /* _STLP_DONT_TEST_RETURN_VOID */
|
|
77 |
|
|
78 |
// mem_fun
|
|
79 |
|
|
80 |
mem_fun(&Class::f0)(&obj);
|
|
81 |
mem_fun(&Class::f1)(&obj, s1);
|
|
82 |
|
|
83 |
#ifndef _STLP_DONT_TEST_RETURN_VOID
|
|
84 |
mem_fun(&Class::vf0)(&obj);
|
|
85 |
mem_fun(&Class::vf1)(&obj, s1);
|
|
86 |
#endif /* _STLP_DONT_TEST_RETURN_VOID */
|
|
87 |
|
|
88 |
// mem_fun (const)
|
|
89 |
|
|
90 |
mem_fun(&Class::f0c)(&objc);
|
|
91 |
mem_fun(&Class::f1c)(&objc, s1);
|
|
92 |
|
|
93 |
#ifndef _STLP_DONT_TEST_RETURN_VOID
|
|
94 |
mem_fun(&Class::vf0c)(&objc);
|
|
95 |
mem_fun(&Class::vf1c)(&objc, s1);
|
|
96 |
#endif /* _STLP_DONT_TEST_RETURN_VOID */
|
|
97 |
|
|
98 |
// mem_fun_ref
|
|
99 |
|
|
100 |
mem_fun_ref(&Class::f0)(obj);
|
|
101 |
mem_fun_ref(&Class::f1)(obj, s1);
|
|
102 |
|
|
103 |
#ifndef _STLP_DONT_TEST_RETURN_VOID
|
|
104 |
mem_fun_ref(&Class::vf0)(obj);
|
|
105 |
mem_fun_ref(&Class::vf1)(obj, s1);
|
|
106 |
#endif /* _STLP_DONT_TEST_RETURN_VOID */
|
|
107 |
|
|
108 |
// mem_fun_ref (const)
|
|
109 |
|
|
110 |
mem_fun_ref(&Class::f0c)(objc);
|
|
111 |
mem_fun_ref(&Class::f1c)(objc, s1);
|
|
112 |
|
|
113 |
#ifndef _STLP_DONT_TEST_RETURN_VOID
|
|
114 |
mem_fun_ref(&Class::vf0c)(objc);
|
|
115 |
mem_fun_ref(&Class::vf1c)(objc, s1);
|
|
116 |
#endif /* _STLP_DONT_TEST_RETURN_VOID */
|
|
117 |
|
|
118 |
return 0;
|
|
119 |
}
|
|
120 |
|
|
121 |
int f1(S1&)
|
|
122 |
{return 1;}
|
|
123 |
|
|
124 |
int f2(S1&, S2&)
|
|
125 |
{return 2;}
|
|
126 |
|
|
127 |
int f1c(const S1&)
|
|
128 |
{return 1;}
|
|
129 |
|
|
130 |
int f2c(const S1&, const S2&)
|
|
131 |
{return 2;}
|
|
132 |
|
|
133 |
void vf1(S1&)
|
|
134 |
{}
|
|
135 |
|
|
136 |
void vf2(S1&, S2&)
|
|
137 |
{}
|
|
138 |
|
|
139 |
void vf1c(const S1&)
|
|
140 |
{}
|
|
141 |
|
|
142 |
void vf2c(const S1&, const S2&)
|
|
143 |
{}
|
|
144 |
|
|
145 |
int Class::f0()
|
|
146 |
{return 0;}
|
|
147 |
|
|
148 |
int Class::f1(const S1&)
|
|
149 |
{return 1;}
|
|
150 |
|
|
151 |
void Class::vf0()
|
|
152 |
{}
|
|
153 |
|
|
154 |
void Class::vf1(const S1&)
|
|
155 |
{}
|
|
156 |
|
|
157 |
int Class::f0c() const
|
|
158 |
{return 0;}
|
|
159 |
|
|
160 |
int Class::f1c(const S1&) const
|
|
161 |
{return 1;}
|
|
162 |
|
|
163 |
void Class::vf0c() const
|
|
164 |
{}
|
|
165 |
|
|
166 |
void Class::vf1c(const S1&) const
|
|
167 |
{}
|
|
168 |
|
|
169 |
|
|
170 |
#ifdef _STLP_DONT_TEST_RETURN_VOID
|
|
171 |
#undef _STLP_DONT_TEST_RETURN_VOID
|
|
172 |
#endif
|