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