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