File: is_nothrow_invocable_r_test.cpp

package info (click to toggle)
boost1.90 1.90.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 593,156 kB
  • sloc: cpp: 4,190,642; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,776; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (288 lines) | stat: -rw-r--r-- 15,408 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#include <boost/compat/invoke.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>

struct F
{
    void operator()()
    {
    }

    char operator()( char x1 ) noexcept
    {
        return x1;
    }

    int operator()( int x1, int x2 ) const
    {
        return 10*x1+x2;
    }

    double operator()( float x1, float x2, float x3 ) const noexcept
    {
        return 100*x1 + 10*x2 + x3;
    }
};

struct X
{
};

struct Y
{
    Y( int );
    Y( double ) noexcept;
};

int main()
{
    using boost::compat::is_nothrow_invocable_r;

    // nonfunction

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, int, int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, int, int, int> ));

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, int, int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, int, int, int> ));

    // function reference

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, void(&)()> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, char(&)(int), char> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, int(&)(int, int), int, int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, double(&)(double, double, double), float, float, float> ));

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, void(&)()> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, char(&)(int), char> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, int(&)(int, int), int, int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, double(&)(double, double, double), float, float, float> ));

#if defined(__cpp_noexcept_function_type)

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, void(&)() noexcept> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<long, char(&)(int) noexcept, char> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<long, int(&)(int, int) noexcept, int, int> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<long, double(&)(double, double, double) noexcept, float, float, float> ));

    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<void, void(&)() noexcept> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<void, char(&)(int) noexcept, char> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<void, int(&)(int, int) noexcept, int, int> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<void, double(&)(double, double, double) noexcept, float, float, float> ));

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<X, void(&)() noexcept> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<X, char(&)(int) noexcept, char> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<X, int(&)(int, int) noexcept, int, int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<X, double(&)(double, double, double) noexcept, float, float, float> ));

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<Y, void(&)() noexcept> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<Y, char(&)(int) noexcept, char> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<Y, int(&)(int, int) noexcept, int, int> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<Y, double(&)(double, double, double) noexcept, float, float, float> ));

#endif

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, void(&)(), int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, char(&)(int)> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, char(&)(int), int, int> ));

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, void(&)(), int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, char(&)(int)> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, char(&)(int), int, int> ));

    // function pointer

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, void(*)()> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, char(*)(int), char> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, int(*)(int, int), int, int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, double(*)(double, double, double), float, float, float> ));

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, void(*)()> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, char(*)(int), char> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, int(*)(int, int), int, int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, double(*)(double, double, double), float, float, float> ));

#if defined(__cpp_noexcept_function_type)

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, void(*)() noexcept> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<long, char(*)(int) noexcept, char> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<long, int(*)(int, int) noexcept, int, int> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<long, double(*)(double, double, double) noexcept, float, float, float> ));

    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<void, void(*)() noexcept> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<void, char(*)(int) noexcept, char> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<void, int(*)(int, int) noexcept, int, int> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<void, double(*)(double, double, double) noexcept, float, float, float> ));

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<X, void(*)() noexcept> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<X, char(*)(int) noexcept, char> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<X, int(*)(int, int) noexcept, int, int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<X, double(*)(double, double, double) noexcept, float, float, float> ));

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<Y, void(*)() noexcept> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<Y, char(*)(int) noexcept, char> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<Y, int(*)(int, int) noexcept, int, int> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<Y, double(*)(double, double, double) noexcept, float, float, float> ));

#endif

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, void(*)(), int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, char(*)(int)> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, char(*)(int), int, int> ));

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, void(*)(), int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, char(*)(int)> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, char(*)(int), int, int> ));

    // object

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, F> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, F, int, int> ));

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, F> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, F, int, int> ));

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<X, F> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<X, F, int, int> ));

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<Y, F> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<Y, F, int, int> ));

#if !BOOST_WORKAROUND(BOOST_MSVC, < 1910)

    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<long, F, char> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<long, F, float, float, float> ));

    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<void, F, char> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<void, F, float, float, float> ));

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<X, F, char> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<X, F, float, float, float> ));

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<Y, F, char> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<Y, F, float, float, float> ));

#endif

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, F, int, int, int, int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, F const> ));

    // member function pointer

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, void(X::*)(), X> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, char(X::*)(int), X, char> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, int(X::*)(int, int), X, int, int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, double(X::*)(double, double, double), X, float, float, float> ));

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, void(X::*)(), X> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, char(X::*)(int), X, char> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, int(X::*)(int, int), X, int, int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, double(X::*)(double, double, double), X, float, float, float> ));

#if defined(__cpp_noexcept_function_type)

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, void(X::*)() noexcept, X> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<long, char(X::*)(int) noexcept, X, char> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<long, int(X::*)(int, int) noexcept, X, int, int> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<long, double(X::*)(double, double, double) noexcept, X, float, float, float> ));

    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<void, void(X::*)() noexcept, X> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<void, char(X::*)(int) noexcept, X, char> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<void, int(X::*)(int, int) noexcept, X, int, int> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<void, double(X::*)(double, double, double) noexcept, X, float, float, float> ));

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<X, void(X::*)() noexcept, X> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<X, char(X::*)(int) noexcept, X, char> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<X, int(X::*)(int, int) noexcept, X, int, int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<X, double(X::*)(double, double, double) noexcept, X, float, float, float> ));

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<Y, void(X::*)() noexcept, X> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<Y, char(X::*)(int) noexcept, X, char> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<Y, int(X::*)(int, int) noexcept, X, int, int> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<Y, double(X::*)(double, double, double) noexcept, X, float, float, float> ));

#endif

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, void(X::*)()> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, void(X::*)(), int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, void(X::*)(), X, int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, char(X::*)(int)> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, char(X::*)(int), int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, char(X::*)(int), X> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, char(X::*)(int), X, int, int> ));

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, void(X::*)()> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, void(X::*)(), int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, void(X::*)(), X, int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, char(X::*)(int)> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, char(X::*)(int), int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, char(X::*)(int), X> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, char(X::*)(int), X, int, int> ));

    // member data pointer

#if !BOOST_WORKAROUND(BOOST_MSVC, < 1910)

    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<long, int X::*, X> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<long, int X::*, X const> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<long, int X::*, X&> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<long, int X::*, X const&> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<long, int X::*, X*> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<long, int X::*, X const*> ));

    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<void, int X::*, X> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<void, int X::*, X const> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<void, int X::*, X&> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<void, int X::*, X const&> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<void, int X::*, X*> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<void, int X::*, X const*> ));

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<X, int X::*, X> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<X, int X::*, X const> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<X, int X::*, X&> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<X, int X::*, X const&> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<X, int X::*, X*> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<X, int X::*, X const*> ));

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<Y, int X::*, X> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<Y, int X::*, X const> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<Y, int X::*, X&> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<Y, int X::*, X const&> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<Y, int X::*, X*> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<Y, int X::*, X const*> ));

    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<Y, double X::*, X> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<Y, double X::*, X const> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<Y, double X::*, X&> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<Y, double X::*, X const&> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<Y, double X::*, X*> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<Y, double X::*, X const*> ));

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<int&, int X::*, X> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<int&, int X::*, X const> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<int&, int X::*, X&> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<int&, int X::*, X const&> ));
    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<int&, int X::*, X*> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<int&, int X::*, X const*> ));

    BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable_r<int&&, int X::*, X> ));

#endif

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, int X::*> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, int X::*, int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<long, int X::*, X, int> ));

    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, int X::*> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, int X::*, int> ));
    BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable_r<void, int X::*, X, int> ));

    return boost::report_errors();
}