Classdesc 3.44
functiondb2.h
1#ifndef CLASSDESC_FUNCTIONDB2
2#define CLASSDESC_FUNCTIONDB2
3template <class R, class A1, class A2>
4struct Arg<R (*)(A1,A2), 1>
5{
6 typedef A1 T;
7 typedef T type;
8};
9
10template <class C, class R, class A1, class A2>
11struct Arg<R (C::*)(A1,A2), 1>
12{
13 typedef A1 T;
14 typedef T type;
15};
16
17template <class C, class R, class A1, class A2>
18struct Arg<R (C::*)(A1,A2) const, 1>
19{
20 typedef A1 T;
21 typedef T type;
22};
23
24#if defined(__cplusplus) && __cplusplus>=201703L
25// noexcept methods
26template <class R, class A1, class A2>
27struct Arg<R (*)(A1,A2) noexcept, 1>
28{
29 typedef A1 T;
30 typedef T type;
31};
32
33template <class C, class R, class A1, class A2>
34struct Arg<R (C::*)(A1,A2) noexcept, 1>
35{
36 typedef A1 T;
37 typedef T type;
38};
39
40template <class C, class R, class A1, class A2>
41struct Arg<R (C::*)(A1,A2) const noexcept, 1>
42{
43 typedef A1 T;
44 typedef T type;
45};
46#endif
47template <class R, class A1, class A2>
48struct Arg<R (*)(A1,A2), 2>
49{
50 typedef A2 T;
51 typedef T type;
52};
53
54template <class C, class R, class A1, class A2>
55struct Arg<R (C::*)(A1,A2), 2>
56{
57 typedef A2 T;
58 typedef T type;
59};
60
61template <class C, class R, class A1, class A2>
62struct Arg<R (C::*)(A1,A2) const, 2>
63{
64 typedef A2 T;
65 typedef T type;
66};
67
68#if defined(__cplusplus) && __cplusplus>=201703L
69// noexcept methods
70template <class R, class A1, class A2>
71struct Arg<R (*)(A1,A2) noexcept, 2>
72{
73 typedef A2 T;
74 typedef T type;
75};
76
77template <class C, class R, class A1, class A2>
78struct Arg<R (C::*)(A1,A2) noexcept, 2>
79{
80 typedef A2 T;
81 typedef T type;
82};
83
84template <class C, class R, class A1, class A2>
85struct Arg<R (C::*)(A1,A2) const noexcept, 2>
86{
87 typedef A2 T;
88 typedef T type;
89};
90#endif
91template <class F, template<class> class P>
92struct AllArgs<F,P,2>
93{
94 static const bool value=true && P<typename Arg<F,1>::T>::value && P<typename Arg<F,2>::T>::value;
95};
96
97
98template <class R, class A1, class A2>
99struct Arity<R (*)(A1,A2)>
100{
101 static const int V=2;
102 static const int value=2;
103};
104
105template <class R, class A1, class A2>
106struct Return<R (*)(A1,A2)>
107{
108 typedef R T;
109 typedef R type;
110};
111
112template <class C,class R, class A1, class A2>
113struct Arity<R (* C::*)(A1,A2)>
114{
115 static const int V=2;
116 static const int value=2;
117};
118
119template <class C,class R, class A1, class A2>
120struct Return<R (* C::*)(A1,A2)>
121{
122 typedef R T;
123 typedef R type;
124};
125
126template <class C, class R, class A1, class A2>
127struct Arity<R (C::*)(A1,A2)>
128{
129 static const int V=2;
130 static const int value=2;
131};
132
133template <class C, class R, class A1, class A2>
134struct Return<R (C::*)(A1,A2)>
135{
136 typedef R T;
137 typedef R type;
138};
139
140template <class C, class R, class A1, class A2>
141struct Arity<R (C::*)(A1,A2) const>
142{
143 static const int V=2;
144 static const int value=2;
145};
146
147template <class C, class R, class A1, class A2>
148struct Return<R (C::*)(A1,A2) const>
149{
150 typedef R T;
151 typedef R type;
152};
153
154template <class C, class R, class A1, class A2>
155struct ClassOf<R (C::*)(A1,A2)>
156{
157 typedef C T;
158 typedef C type;
159};
160
161template <class C, class R, class A1, class A2>
162struct ClassOf<R (*C::*)(A1,A2)>
163{
164 typedef C T;
165 typedef C type;
166};
167
168template <class C, class R, class A1, class A2>
169struct ClassOf<R (C::*)(A1,A2) const>
170{
171 typedef C T;
172 typedef C type;
173};
174
175template <class C, class R, class A1, class A2>
176struct is_member_function_ptr<R (C::*)(A1,A2)>
177{
178 static const bool value=true;
179};
180
181template <class C, class R, class A1, class A2>
182struct is_member_function_ptr<R (C::*)(A1,A2) const>
183{
184 static const bool value=true;
185};
186
187template <class C, class R, class A1, class A2>
188struct is_const_method<R (C::*)(A1,A2) const>
189{
190 static const bool value=true;
191};
192
193template <class R, class A1, class A2>
194struct is_nonmember_function_ptr<R (*)(A1,A2)>
195{
196 static const bool value=true;
197};
198
199template <class C, class R, class A1, class A2>
200struct is_nonmember_function_ptr<R (*C::*)(A1,A2)>
201{
202 static const bool value=true;
203};
204
205template <class C, class D, class R, class A1, class A2>
206class bound_method<C, R (D::*)(A1,A2)>
207{
208 typedef R (D::*M)(A1,A2);
209 C* obj;
210 M method;
211 public:
212 static const int arity=2;
213 typedef R Ret;
214 template <int i> struct Arg: public functional::Arg<M,i> {};
215 bound_method(C& obj, M method): obj(&obj), method(method) {}
216 typename enable_if<Not<classdesc::is_const<C> >, R>::T
217 operator()(A1 a1,A2 a2) const {return (obj->*method)(a1,a2);}
218 void rebind(C& newObj) {obj=&newObj;}
219 static const bool is_const=false;
220};
221
222template <class C, class D, class R, class A1, class A2>
223class bound_method<const C, R (D::*)(A1,A2)>
224{
225 typedef R (D::*M)(A1,A2);
226 const C* obj;
227 M method;
228 public:
229 static const int arity=2;
230 typedef R Ret;
231 template <int i> struct Arg: public functional::Arg<M,i> {};
232 bound_method(const C& obj, M method): obj(&obj), method(method) {}
233 R operator()(A1 a1,A2 a2) const {
234 throw std::runtime_error("cannot call method, inappropriate argument type");
235 }
236 void rebind(C& newObj) {obj=&newObj;}
237 static const bool is_const=false;
238};
239
240template <class C, class D, class R, class A1, class A2>
241class bound_method<C, R (D::*)(A1,A2) const>
242{
243 typedef R (D::*M)(A1,A2) const;
244 C& obj;
245 M method;
246 public:
247 static const int arity=2;
248 typedef R Ret;
249 template <int i> struct Arg: public functional::Arg<M,i> {};
250 bound_method(C& obj, M method): obj(obj), method(method) {}
251 R operator()(A1 a1,A2 a2) const {return (obj.*method)(a1,a2);}
252 static const bool is_const=true;
253};
254
255#if defined(__cplusplus) && __cplusplus>=201703L
256// noexcept methods
257
258template <class R, class A1, class A2>
259struct Arity<R (*)(A1,A2) noexcept>
260{
261 static const int V=2;
262 static const int value=2;
263};
264
265template <class R, class A1, class A2>
266struct Return<R (*)(A1,A2) noexcept>
267{
268 typedef R T;
269 typedef R type;
270};
271
272template <class C,class R, class A1, class A2>
273struct Arity<R (* C::*)(A1,A2) noexcept>
274{
275 static const int V=2;
276 static const int value=2;
277};
278
279template <class C,class R, class A1, class A2>
280struct Return<R (* C::*)(A1,A2) noexcept>
281{
282 typedef R T;
283 typedef R type;
284};
285
286template <class C, class R, class A1, class A2>
287struct Arity<R (C::*)(A1,A2) noexcept>
288{
289 static const int V=2;
290 static const int value=2;
291};
292
293template <class C, class R, class A1, class A2>
294struct Return<R (C::*)(A1,A2) noexcept>
295{
296 typedef R T;
297 typedef R type;
298};
299
300template <class C, class R, class A1, class A2>
301struct Arity<R (C::*)(A1,A2) const noexcept>
302{
303 static const int V=2;
304 static const int value=2;
305};
306
307template <class C, class R, class A1, class A2>
308struct Return<R (C::*)(A1,A2) const noexcept>
309{
310 typedef R T;
311 typedef R type;
312};
313
314template <class C, class R, class A1, class A2>
315struct ClassOf<R (C::*)(A1,A2) noexcept>
316{
317 typedef C T;
318 typedef C type;
319};
320
321template <class C, class R, class A1, class A2>
322struct ClassOf<R (*C::*)(A1,A2) noexcept>
323{
324 typedef C T;
325 typedef C type;
326};
327
328template <class C, class R, class A1, class A2>
329struct ClassOf<R (C::*)(A1,A2) const noexcept>
330{
331 typedef C T;
332 typedef C type;
333};
334
335template <class C, class R, class A1, class A2>
336struct is_member_function_ptr<R (C::*)(A1,A2) noexcept>
337{
338 static const bool value=true;
339};
340
341template <class C, class R, class A1, class A2>
342struct is_member_function_ptr<R (C::*)(A1,A2) const noexcept>
343{
344 static const bool value=true;
345};
346
347template <class C, class R, class A1, class A2>
348struct is_const_method<R (C::*)(A1,A2) const noexcept>
349{
350 static const bool value=true;
351};
352
353template <class R, class A1, class A2>
354struct is_nonmember_function_ptr<R (*)(A1,A2) noexcept>
355{
356 static const bool value=true;
357};
358
359template <class C, class R, class A1, class A2>
360struct is_nonmember_function_ptr<R (*C::*)(A1,A2) noexcept>
361{
362 static const bool value=true;
363};
364
365template <class C, class D, class R, class A1, class A2>
366class bound_method<C, R (D::*)(A1,A2) noexcept>
367{
368 typedef R (D::*M)(A1,A2);
369 C* obj;
370 M method;
371 public:
372 static const int arity=2;
373 typedef R Ret;
374 template <int i> struct Arg: public functional::Arg<M,i> {};
375 bound_method(C& obj, M method): obj(&obj), method(method) {}
376 typename enable_if<Not<classdesc::is_const<C> >, R>::T
377 operator()(A1 a1,A2 a2) const {return (obj->*method)(a1,a2);}
378 void rebind(C& newObj) {obj=&newObj;}
379 static const bool is_const=false;
380};
381
382template <class C, class D, class A1, class A2>
383class bound_method<C, void (D::*)(A1,A2) noexcept>
384{
385 typedef void (D::*M)(A1,A2);
386 C* obj;
387 M method;
388 public:
389 static const int arity=2;
390 typedef void Ret;
391 template <int i> struct Arg: public functional::Arg<M,i> {};
392 bound_method(C& obj, M method): obj(&obj), method(method) {}
393 typename enable_if<Not<classdesc::is_const<C> > >::T
394 operator()(A1 a1,A2 a2) const {(obj->*method)(a1,a2);}
395 void rebind(C& newObj) {obj=&newObj;}
396 static const bool is_const=false;
397};
398
399template <class C, class D, class R, class A1, class A2>
400class bound_method<const C, R (D::*)(A1,A2) noexcept>
401{
402 typedef R (D::*M)(A1,A2);
403 const C* obj;
404 M method;
405 public:
406 static const int arity=2;
407 typedef R Ret;
408 template <int i> struct Arg: public functional::Arg<M,i> {};
409 bound_method(const C& obj, M method): obj(&obj), method(method) {}
410 R operator()(A1 a1,A2 a2) const {
411 throw std::runtime_error("cannot call method, inappropriate argument type");
412 }
413 void rebind(C& newObj) {obj=&newObj;}
414 static const bool is_const=false;
415};
416
417template <class C, class D, class A1, class A2>
418class bound_method<const C, void (D::*)(A1,A2) noexcept>
419{
420 typedef void (D::*M)(A1,A2);
421 const C* obj;
422 M method;
423 public:
424 static const int arity=2;
425 typedef void Ret;
426 template <int i> struct Arg: public functional::Arg<M,i> {};
427 bound_method(const C& obj, M method): obj(&obj), method(method) {}
428 typename enable_if<Not<classdesc::is_const<C> > >::T
429 operator()(A1 a1,A2 a2) const {
430 throw std::runtime_error("cannot call method, inappropriate argument type");
431 }
432 void rebind(C& newObj) {obj=&newObj;}
433 static const bool is_const=false;
434};
435
436template <class C, class D, class R, class A1, class A2>
437class bound_method<C, R (D::*)(A1,A2) const noexcept>
438{
439 typedef R (D::*M)(A1,A2) const;
440 C& obj;
441 M method;
442 public:
443 static const int arity=2;
444 typedef R Ret;
445 template <int i> struct Arg: public functional::Arg<M,i> {};
446 bound_method(C& obj, M method): obj(obj), method(method) {}
447 R operator()(A1 a1,A2 a2) const {return (obj.*method)(a1,a2);}
448 static const bool is_const=true;
449};
450
451template <class C, class D, class A1, class A2>
452class bound_method<C, void (D::*)(A1,A2) const noexcept>
453{
454 typedef void (D::*M)(A1,A2) const;
455 C& obj;
456 M method;
457 public:
458 static const int arity=2;
459 typedef void Ret;
460 template <int i> struct Arg: public functional::Arg<M,i> {};
461 bound_method(C& obj, M method): obj(obj), method(method) {}
462 void operator()(A1 a1,A2 a2) const {(obj.*method)(a1,a2);}
463 static const bool is_const=true;
464};
465#endif
466
467template <class F, class Args>
468typename enable_if<And<AllArgs<F, is_rvalue>, Eq<Arity<F>::value, 2> >,
469 typename Return<F>::T>::T
470apply_nonvoid_fn(F f, Args& a, Fdummy<F> dum=0)
471{
472 return f(a[0],a[1]);
473}
474
475/*
476 TODO: if any of the arguments to f are lvalues, we need to construct temporaries,
477 which require C++-11 ability to test for the existence of a copy constructor.
478 If the return type is not copy constructable, the user must arrange for the return value to be discarded
479*/
480
481template <class F, class Args>
482typename enable_if<And<AllArgs<F, is_rvalue>, Eq<Arity<F>::value, 2> >,
483 void>::T
484apply_void_fn(F f, Args& a, Fdummy<F> dum=0)
485{
486 f(a[0],a[1]);
487}
488
489template <class Buffer, class F>
490typename enable_if<Eq<Arity<F>::value, 2>, typename Return<F>::T>::T
491callOnBuffer(Buffer& buffer, F f)
492{
493 typename remove_const<typename remove_reference<typename Arg<F,1>::T>::type>::type a1;
494 buffer>>a1;
495 typename remove_const<typename remove_reference<typename Arg<F,2>::T>::type>::type a2;
496 buffer>>a2;
497 return f(
498a1
499,
500a2
501 );
502}
503#endif
Definition functiondb2.h:214