00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef __MMX_FUNCTION_HPP
00014 #define __MMX_FUNCTION_HPP
00015 #include <basix/operators.hpp>
00016
00017 namespace mmx {
00018
00019 template<typename T> inline syntactic flatten_type () {
00020 return as_syntactic (type_name (type_information<T>::id)); }
00021
00022
00023
00024
00025
00026 template<typename T>
00027 struct argument_helper {
00028 typedef const T& arg_type;
00029 };
00030
00031 template<typename T>
00032 struct argument_helper<T&> {
00033 typedef T& arg_type;
00034 };
00035
00036 template<typename T>
00037 struct argument_helper<T*> {
00038 typedef T* arg_type;
00039 };
00040
00041 template<typename T>
00042 struct argument_helper<const T&> {
00043 typedef const T& arg_type;
00044 };
00045
00046 template<typename T>
00047 struct argument_helper<const T*> {
00048 typedef const T* arg_type;
00049 };
00050
00051 #define Argument(T) typename argument_helper<T>::arg_type
00052
00053
00054
00055
00056
00057 template<typename D>
00058 struct function_0_rep REP_STRUCT {
00059 inline function_0_rep () {}
00060 virtual ~function_0_rep () {}
00061 virtual D apply () = 0;
00062 };
00063
00064 template<typename D>
00065 struct def_function_0_rep: public function_0_rep<D> {
00066 D (*fun) ();
00067 inline def_function_0_rep (D (*fun2) ()): fun (fun2) {}
00068 D apply () { return fun (); }
00069 };
00070
00071 template<typename D>
00072 struct function_0 {
00073 function_0_rep<D>* rep;
00074 inline function_0 (): rep (NULL) {}
00075 inline function_0 (function_0_rep<D>* rep2): rep (rep2) {}
00076 inline function_0 (function_0_rep<D>* rep2, bool with_inc):
00077 rep (rep2) { (void) with_inc; INC_COUNT (rep); }
00078 inline function_0 (const function_0& f):
00079 rep (f.rep) { INC_NULL_COUNT(rep); }
00080 inline function_0 (D (*fun) ()):
00081 rep (new def_function_0_rep<D> (fun)) {}
00082 inline ~function_0 () { DEC_NULL_COUNT (rep); }
00083 inline function_0& operator = (const function_0& f) {
00084 INC_NULL_COUNT (f.rep); DEC_NULL_COUNT (rep);
00085 rep= f.rep; return *this; }
00086 inline D operator () () const { return rep->apply (); }
00087 };
00088
00089 #define TMPL template<typename D>
00090 #define Function function_0<D>
00091 #define Function_rep function_0_rep<D>
00092 TMPL inline Function_rep* inside (const Function& f) { return f.rep; }
00093 TMPL inline syntactic flatten (const Function& f) {
00094 return apply ("function", flatten_type<D> ()); }
00095 TMPL inline nat hard_hash (const Function& f) {
00096 return as_hash (f.rep); }
00097 TMPL inline bool hard_eq (const Function& f, const Function& g) {
00098 return (f.rep) == (g.rep); }
00099 TMPL inline bool hard_neq (const Function& f, const Function& g) {
00100 return (f.rep) != (g.rep); }
00101 HARD_TO_EXACT_IDENTITY_SUGAR(TMPL,Function)
00102 HARD_TO_TRUE_IDENTITY_SUGAR(TMPL,Function)
00103 TMPL inline bool is_nil (const Function& f) {
00104 return (void*) inside (f) == NULL; }
00105 #undef Function_rep
00106 #undef Function
00107 #undef TMPL
00108
00109
00110
00111
00112
00113 template<typename D, typename S1>
00114 struct function_1_rep REP_STRUCT {
00115 inline function_1_rep () {}
00116 virtual ~function_1_rep () {}
00117 virtual D apply (S1 x1) = 0;
00118 };
00119
00120 template<typename D, typename S1>
00121 struct def_function_1_rep: public function_1_rep<D,S1> {
00122 D (*fun) (S1);
00123 inline def_function_1_rep (D (*fun2) (S1)): fun (fun2) {}
00124 D apply (S1 x1) { return fun (x1); }
00125 };
00126
00127 template<typename D, typename S1>
00128 struct function_1 {
00129 function_1_rep<D,S1>* rep;
00130 inline function_1 (): rep (NULL) {}
00131 inline function_1 (function_1_rep<D,S1>* rep2): rep (rep2) {}
00132 inline function_1 (function_1_rep<D,S1>* rep2, bool with_inc):
00133 rep (rep2) { (void) with_inc; INC_COUNT (rep); }
00134 inline function_1 (const function_1& f):
00135 rep (f.rep) { INC_NULL_COUNT(rep); }
00136 inline function_1 (D (*fun) (S1)):
00137 rep (new def_function_1_rep<D,S1> (fun)) {}
00138 inline ~function_1 () { DEC_NULL_COUNT (rep); }
00139 inline function_1& operator = (const function_1& f) {
00140 INC_NULL_COUNT (f.rep); DEC_NULL_COUNT (rep);
00141 rep= f.rep; return *this; }
00142 inline D operator () (S1 x1) const { return rep->apply (x1); }
00143 };
00144
00145 #define TMPL template<typename D, typename S1>
00146 #define Function function_1<D,S1>
00147 #define Function_rep function_1_rep<D,S1>
00148 TMPL inline Function_rep* inside (const Function& f) { return f.rep; }
00149 TMPL inline syntactic flatten (const Function& f) {
00150 return apply ("function", flatten_type<S1> (), flatten_type<D> ()); }
00151 TMPL inline nat hard_hash (const Function& f) {
00152 return as_hash (f.rep); }
00153 TMPL inline bool hard_eq (const Function& f, const Function& g) {
00154 return (f.rep) == (g.rep); }
00155 TMPL inline bool hard_neq (const Function& f, const Function& g) {
00156 return (f.rep) != (g.rep); }
00157 HARD_TO_EXACT_IDENTITY_SUGAR(TMPL,Function)
00158 HARD_TO_TRUE_IDENTITY_SUGAR(TMPL,Function)
00159 TMPL inline bool is_nil (const Function& f) {
00160 return (void*) inside (f) == NULL; }
00161 #undef Function_rep
00162 #undef Function
00163 #undef TMPL
00164
00165 template<typename FT, typename R, typename C, typename Fun>
00166 struct format_function_helper {
00167 static inline format<R>
00168 op (const Fun& fun, const format<C>& fm) {
00169 return get_format (fun (get_sample (fm))); }
00170 };
00171
00172 template<typename FT, typename C, typename Fun>
00173 struct format_function_helper<FT,C,C,Fun> {
00174 static inline format<C>
00175 op (const Fun&, const format<C>& fm) {
00176 return fm; }
00177 };
00178
00179 template<typename R, typename C, typename Fun>
00180 struct format_function_helper<empty_format,R,C,Fun> {
00181 static inline format<R>
00182 op (const Fun& fun, const format<C>&) {
00183 return format<R> (); }
00184 };
00185
00186 template<typename C, typename Fun>
00187 struct format_function_helper<empty_format,C,C,Fun> {
00188 static inline format<C>
00189 op (const Fun&, const format<C>& fm) {
00190 return fm; }
00191 };
00192
00193 template<typename C, typename R> format<R>
00194 map (const function_1<R,Argument(C) >& fun, const format<C>& fm) {
00195 typedef function_1<R,Argument(C) > Fun;
00196 typedef typename format<R>::FT FT;
00197 return format_function_helper<FT,R,C,Fun>::op (fun, fm);
00198 }
00199
00200 template<typename C, typename R> format<R>
00201 map (R (*fun) (const C&), const format<C>& fm) {
00202 typedef R (*Fun) (const C&);
00203 typedef typename format<R>::FT FT;
00204 return format_function_helper<FT,R,C,Fun>::op (fun, fm);
00205 }
00206
00207
00208
00209
00210
00211 template<typename D, typename S1, typename S2>
00212 struct function_2_rep REP_STRUCT {
00213 inline function_2_rep () {}
00214 virtual ~function_2_rep () {}
00215 virtual D apply (S1 x1, S2 x2) = 0;
00216 };
00217
00218 template<typename D, typename S1, typename S2>
00219 struct def_function_2_rep: public function_2_rep<D,S1,S2> {
00220 D (*fun) (S1, S2);
00221 inline def_function_2_rep (D (*fun2) (S1, S2)): fun (fun2) {}
00222 D apply (S1 x1, S2 x2) { return fun (x1, x2); }
00223 };
00224
00225 template<typename D, typename S1, typename S2>
00226 struct function_2 {
00227 function_2_rep<D,S1,S2>* rep;
00228 inline function_2 (): rep (NULL) {}
00229 inline function_2 (function_2_rep<D,S1,S2>* rep2): rep (rep2) {}
00230 inline function_2 (function_2_rep<D,S1,S2>* rep2, bool with_inc):
00231 rep (rep2) { (void) with_inc; INC_COUNT (rep); }
00232 inline function_2 (const function_2& f):
00233 rep (f.rep) { INC_NULL_COUNT(rep); }
00234 inline function_2 (D (*fun) (S1, S2)):
00235 rep (new def_function_2_rep<D,S1,S2> (fun)) {}
00236 inline ~function_2 () { DEC_NULL_COUNT (rep); }
00237 inline function_2& operator = (const function_2& f) {
00238 INC_NULL_COUNT (f.rep); DEC_NULL_COUNT (rep);
00239 rep= f.rep; return *this; }
00240 inline D operator () (S1 x1, S2 x2) const {
00241 return rep->apply (x1, x2); }
00242 };
00243
00244 #define TMPL template<typename D, typename S1, typename S2>
00245 #define Function function_2<D,S1,S2>
00246 #define Function_rep function_2_rep<D,S1,S2>
00247 TMPL inline Function_rep* inside (const Function& f) { return f.rep; }
00248 TMPL inline syntactic flatten (const Function& f) {
00249 return apply ("function",
00250 flatten_type<S1> (), flatten_type<S2> (), flatten_type<D> ()); }
00251 TMPL inline nat hard_hash (const Function& f) {
00252 return as_hash (f.rep); }
00253 TMPL inline bool hard_eq (const Function& f, const Function& g) {
00254 return (f.rep) == (g.rep); }
00255 TMPL inline bool hard_neq (const Function& f, const Function& g) {
00256 return (f.rep) != (g.rep); }
00257 HARD_TO_EXACT_IDENTITY_SUGAR(TMPL,Function)
00258 HARD_TO_TRUE_IDENTITY_SUGAR(TMPL,Function)
00259 TMPL inline bool is_nil (const Function& f) {
00260 return (void*) inside (f) == NULL; }
00261 #undef Function_rep
00262 #undef Function
00263 #undef TMPL
00264
00265
00266
00267
00268
00269 template<typename D, typename S1, typename S2, typename S3>
00270 struct function_3_rep REP_STRUCT {
00271 inline function_3_rep () {}
00272 virtual ~function_3_rep () {}
00273 virtual D apply (S1 x1, S2 x2, S3 x3) = 0;
00274 };
00275
00276 template<typename D, typename S1, typename S2, typename S3>
00277 struct def_function_3_rep: public function_3_rep<D,S1,S2,S3> {
00278 D (*fun) (S1, S2, S3);
00279 inline def_function_3_rep (D (*fun2) (S1, S2, S3)):
00280 fun (fun2) {}
00281 D apply (S1 x1, S2 x2, S3 x3) {
00282 return fun (x1, x2, x3); }
00283 };
00284
00285 template<typename D, typename S1, typename S2, typename S3>
00286 struct function_3 {
00287 function_3_rep<D,S1,S2,S3>* rep;
00288 inline function_3 (): rep (NULL) {}
00289 inline function_3 (function_3_rep<D,S1,S2,S3>* rep2): rep (rep2) {}
00290 inline function_3 (function_3_rep<D,S1,S2,S3>* rep2, bool with_inc):
00291 rep (rep2) { (void) with_inc; INC_COUNT (rep); }
00292 inline function_3 (const function_3& f):
00293 rep (f.rep) { INC_NULL_COUNT(rep); }
00294 inline function_3 (D (*fun) (S1, S2, S3)):
00295 rep (new def_function_3_rep<D,S1,S2,S3> (fun)) {}
00296 inline ~function_3 () { DEC_NULL_COUNT (rep); }
00297 inline function_3& operator = (const function_3& f) {
00298 INC_NULL_COUNT (f.rep); DEC_NULL_COUNT (rep);
00299 rep= f.rep; return *this; }
00300 inline D operator () (S1 x1, S2 x2, S3 x3) const {
00301 return rep->apply (x1, x2, x3); }
00302 };
00303
00304 #define TMPL template<typename D, typename S1, typename S2, typename S3>
00305 #define Function function_3<D,S1,S2,S3>
00306 #define Function_rep function_3_rep<D,S1,S2,S3>
00307 TMPL inline Function_rep* inside (const Function& f) { return f.rep; }
00308 TMPL inline syntactic flatten (const Function& f) {
00309 return "function"; }
00310 TMPL inline nat hard_hash (const Function& f) {
00311 return as_hash (f.rep); }
00312 TMPL inline bool hard_eq (const Function& f, const Function& g) {
00313 return (f.rep) == (g.rep); }
00314 TMPL inline bool hard_neq (const Function& f, const Function& g) {
00315 return (f.rep) != (g.rep); }
00316 HARD_TO_EXACT_IDENTITY_SUGAR(TMPL,Function)
00317 HARD_TO_TRUE_IDENTITY_SUGAR(TMPL,Function)
00318 TMPL inline bool is_nil (const Function& f) {
00319 return (void*) inside (f) == NULL; }
00320 #undef Function_rep
00321 #undef Function
00322 #undef TMPL
00323
00324
00325
00326
00327
00328 template<typename D, typename S1, typename S2, typename S3, typename S4>
00329 struct function_4_rep REP_STRUCT {
00330 inline function_4_rep () {}
00331 virtual ~function_4_rep () {}
00332 virtual D apply (S1 x1, S2 x2, S3 x3, S4 x4) = 0;
00333 };
00334
00335 template<typename D, typename S1, typename S2, typename S3, typename S4>
00336 struct def_function_4_rep: public function_4_rep<D,S1,S2,S3,S4> {
00337 D (*fun) (S1, S2, S3, S4);
00338 inline def_function_4_rep (D (*fun2) (S1, S2, S3, S4)):
00339 fun (fun2) {}
00340 D apply (S1 x1, S2 x2, S3 x3, S4 x4) {
00341 return fun (x1, x2, x3, x4); }
00342 };
00343
00344 template<typename D, typename S1, typename S2, typename S3, typename S4>
00345 struct function_4 {
00346 function_4_rep<D,S1,S2,S3,S4>* rep;
00347 inline function_4 (): rep (NULL) {}
00348 inline function_4 (function_4_rep<D,S1,S2,S3,S4>* rep2): rep (rep2) {}
00349 inline function_4 (function_4_rep<D,S1,S2,S3,S4>* rep2, bool with_inc):
00350 rep (rep2) { (void) with_inc; INC_COUNT (rep); }
00351 inline function_4 (const function_4& f):
00352 rep (f.rep) { INC_NULL_COUNT(rep); }
00353 inline function_4 (D (*fun) (S1, S2, S3, S4)):
00354 rep (new def_function_4_rep<D,S1,S2,S3,S4> (fun)) {}
00355 inline ~function_4 () { DEC_NULL_COUNT (rep); }
00356 inline function_4& operator = (const function_4& f) {
00357 INC_NULL_COUNT (f.rep); DEC_NULL_COUNT (rep);
00358 rep= f.rep; return *this; }
00359 inline D operator () (S1 x1, S2 x2, S3 x3, S4 x4) const {
00360 return rep->apply (x1, x2, x3, x4); }
00361 };
00362
00363 #define TMPL template<typename D, typename S1, typename S2, typename S3, typename S4>
00364 #define Function function_4<D,S1,S2,S3,S4>
00365 #define Function_rep function_4_rep<D,S1,S2,S3,S4>
00366 TMPL inline Function_rep* inside (const Function& f) { return f.rep; }
00367 TMPL inline syntactic flatten (const Function& f) {
00368 return "function"; }
00369 TMPL inline nat hard_hash (const Function& f) {
00370 return as_hash (f.rep); }
00371 TMPL inline bool hard_eq (const Function& f, const Function& g) {
00372 return (f.rep) == (g.rep); }
00373 TMPL inline bool hard_neq (const Function& f, const Function& g) {
00374 return (f.rep) != (g.rep); }
00375 HARD_TO_EXACT_IDENTITY_SUGAR(TMPL,Function)
00376 HARD_TO_TRUE_IDENTITY_SUGAR(TMPL,Function)
00377 TMPL inline bool is_nil (const Function& f) {
00378 return (void*) inside (f) == NULL; }
00379 #undef Function_rep
00380 #undef Function
00381 #undef TMPL
00382
00383
00384
00385
00386
00387 template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5>
00388 struct function_5_rep REP_STRUCT {
00389 inline function_5_rep () {}
00390 virtual ~function_5_rep () {}
00391 virtual D apply (S1 x1, S2 x2, S3 x3, S4 x4, S5 x5) = 0;
00392 };
00393
00394 template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5>
00395 struct def_function_5_rep: public function_5_rep<D,S1,S2,S3,S4,S5> {
00396 D (*fun) (S1, S2, S3, S4, S5);
00397 inline def_function_5_rep (D (*fun2) (S1, S2, S3, S4, S5)):
00398 fun (fun2) {}
00399 D apply (S1 x1, S2 x2, S3 x3, S4 x4, S5 x5) {
00400 return fun (x1, x2, x3, x4, x5); }
00401 };
00402
00403 template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5>
00404 struct function_5 {
00405 function_5_rep<D,S1,S2,S3,S4,S5>* rep;
00406 inline function_5 (): rep (NULL) {}
00407 inline function_5 (function_5_rep<D,S1,S2,S3,S4,S5>* rep2): rep (rep2) {}
00408 inline function_5 (const function_5& f):
00409 rep (f.rep) { INC_NULL_COUNT(rep); }
00410 inline function_5 (D (*fun) (S1, S2, S3, S4, S5)):
00411 rep (new def_function_5_rep<D,S1,S2,S3,S4,S5> (fun)) {}
00412 inline function_5 (function_5_rep<D,S1,S2,S3,S4,S5>* rep2, bool with_inc):
00413 rep (rep2) { (void) with_inc; INC_COUNT (rep); }
00414 inline ~function_5 () { DEC_NULL_COUNT (rep); }
00415 inline function_5& operator = (const function_5& f) {
00416 INC_NULL_COUNT (f.rep); DEC_NULL_COUNT (rep);
00417 rep= f.rep; return *this; }
00418 inline D operator () (S1 x1, S2 x2, S3 x3, S4 x4, S5 x5) const {
00419 return rep->apply (x1, x2, x3, x4, x5); }
00420 };
00421
00422 #define TMPL template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5>
00423 #define Function function_5<D,S1,S2,S3,S4,S5>
00424 #define Function_rep function_5_rep<D,S1,S2,S3,S4,S5>
00425 TMPL inline Function_rep* inside (const Function& f) { return f.rep; }
00426 TMPL inline syntactic flatten (const Function& f) {
00427 return "function"; }
00428 TMPL inline nat hard_hash (const Function& f) {
00429 return as_hash (f.rep); }
00430 TMPL inline bool hard_eq (const Function& f, const Function& g) {
00431 return (f.rep) == (g.rep); }
00432 TMPL inline bool hard_neq (const Function& f, const Function& g) {
00433 return (f.rep) != (g.rep); }
00434 HARD_TO_EXACT_IDENTITY_SUGAR(TMPL,Function)
00435 HARD_TO_TRUE_IDENTITY_SUGAR(TMPL,Function)
00436 TMPL inline bool is_nil (const Function& f) {
00437 return (void*) inside (f) == NULL; }
00438 #undef Function_rep
00439 #undef Function
00440 #undef TMPL
00441
00442
00443
00444
00445
00446 template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5, typename S6>
00447 struct function_6_rep REP_STRUCT {
00448 inline function_6_rep () {}
00449 virtual ~function_6_rep () {}
00450 virtual D apply (S1 x1, S2 x2, S3 x3, S4 x4, S5 x5, S6 x6) = 0;
00451 };
00452
00453 template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5, typename S6>
00454 struct def_function_6_rep: public function_6_rep<D,S1,S2,S3,S4,S5,S6> {
00455 D (*fun) (S1, S2, S3, S4, S5, S6);
00456 inline def_function_6_rep (D (*fun2) (S1, S2, S3, S4, S5, S6)):
00457 fun (fun2) {}
00458 D apply (S1 x1, S2 x2, S3 x3, S4 x4, S5 x5, S6 x6) {
00459 return fun (x1, x2, x3, x4, x5, x6); }
00460 };
00461
00462 template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5, typename S6>
00463 struct function_6 {
00464 function_6_rep<D,S1,S2,S3,S4,S5,S6>* rep;
00465 inline function_6 (): rep (NULL) {}
00466 inline function_6 (function_6_rep<D,S1,S2,S3,S4,S5,S6>* rep2): rep (rep2) {}
00467 inline function_6 (function_6_rep<D,S1,S2,S3,S4,S5,S6>* rep2, bool with_inc):
00468 rep (rep2) { (void) with_inc; INC_COUNT (rep); }
00469 inline function_6 (const function_6& f):
00470 rep (f.rep) { INC_NULL_COUNT(rep); }
00471 inline function_6 (D (*fun) (S1, S2, S3, S4, S5, S6)):
00472 rep (new def_function_6_rep<D,S1,S2,S3,S4,S5,S6> (fun)) {}
00473 inline ~function_6 () { DEC_NULL_COUNT (rep); }
00474 inline function_6& operator = (const function_6& f) {
00475 INC_NULL_COUNT (f.rep); DEC_NULL_COUNT (rep);
00476 rep= f.rep; return *this; }
00477 inline D operator () (S1 x1, S2 x2, S3 x3, S4 x4, S5 x5, S6 x6) const {
00478 return rep->apply (x1, x2, x3, x4, x5, x6); }
00479 };
00480
00481 #define TMPL template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5, typename S6>
00482 #define Function function_6<D,S1,S2,S3,S4,S5,S6>
00483 #define Function_rep function_6_rep<D,S1,S2,S3,S4,S5,S6>
00484 TMPL inline Function_rep* inside (const Function& f) { return f.rep; }
00485 TMPL inline syntactic flatten (const Function& f) {
00486 return "function"; }
00487 TMPL inline nat hard_hash (const Function& f) {
00488 return as_hash (f.rep); }
00489 TMPL inline bool hard_eq (const Function& f, const Function& g) {
00490 return (f.rep) == (g.rep); }
00491 TMPL inline bool hard_neq (const Function& f, const Function& g) {
00492 return (f.rep) != (g.rep); }
00493 HARD_TO_EXACT_IDENTITY_SUGAR(TMPL,Function)
00494 HARD_TO_TRUE_IDENTITY_SUGAR(TMPL,Function)
00495 TMPL inline bool is_nil (const Function& f) {
00496 return (void*) inside (f) == NULL; }
00497 #undef Function_rep
00498 #undef Function
00499 #undef TMPL
00500
00501
00502
00503
00504
00505 template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5, typename S6, typename S7>
00506 struct function_7_rep REP_STRUCT {
00507 inline function_7_rep () {}
00508 virtual ~function_7_rep () {}
00509 virtual D apply (S1 x1, S2 x2, S3 x3, S4 x4, S5 x5, S6 x6, S7 x7) = 0;
00510 };
00511
00512 template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5, typename S6, typename S7>
00513 struct def_function_7_rep: public function_7_rep<D,S1,S2,S3,S4,S5,S6,S7> {
00514 D (*fun) (S1, S2, S3, S4, S5, S6, S7);
00515 inline def_function_7_rep (D (*fun2) (S1, S2, S3, S4, S5, S6, S7)):
00516 fun (fun2) {}
00517 D apply (S1 x1, S2 x2, S3 x3, S4 x4, S5 x5, S6 x6, S7 x7) {
00518 return fun (x1, x2, x3, x4, x5, x6, x7); }
00519 };
00520
00521 template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5, typename S6, typename S7>
00522 struct function_7 {
00523 function_7_rep<D,S1,S2,S3,S4,S5,S6,S7>* rep;
00524 inline function_7 (): rep (NULL) {}
00525 inline function_7 (function_7_rep<D,S1,S2,S3,S4,S5,S6,S7>* rep2): rep (rep2) {}
00526 inline function_7 (function_7_rep<D,S1,S2,S3,S4,S5,S6,S7>* rep2,
00527 bool with_inc):
00528 rep (rep2) { (void) with_inc; INC_COUNT (rep); }
00529 inline function_7 (const function_7& f):
00530 rep (f.rep) { INC_NULL_COUNT(rep); }
00531 inline function_7 (D (*fun) (S1, S2, S3, S4, S5, S6, S7)):
00532 rep (new def_function_7_rep<D,S1,S2,S3,S4,S5,S6,S7> (fun)) {}
00533 inline ~function_7 () { DEC_NULL_COUNT (rep); }
00534 inline function_7& operator = (const function_7& f) {
00535 INC_NULL_COUNT (f.rep); DEC_NULL_COUNT (rep);
00536 rep= f.rep; return *this; }
00537 inline D operator () (S1 x1, S2 x2, S3 x3, S4 x4, S5 x5, S6 x6, S7 x7) const {
00538 return rep->apply (x1, x2, x3, x4, x5, x6, x7); }
00539 };
00540
00541 #define TMPL template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5, typename S6, typename S7>
00542 #define Function function_7<D,S1,S2,S3,S4,S5,S6,S7>
00543 #define Function_rep function_7_rep<D,S1,S2,S3,S4,S5,S6,S7>
00544 TMPL inline Function_rep* inside (const Function& f) { return f.rep; }
00545 TMPL inline syntactic flatten (const Function& f) {
00546 return "function"; }
00547 TMPL inline nat hard_hash (const Function& f) {
00548 return as_hash (f.rep); }
00549 TMPL inline bool hard_eq (const Function& f, const Function& g) {
00550 return (f.rep) == (g.rep); }
00551 TMPL inline bool hard_neq (const Function& f, const Function& g) {
00552 return (f.rep) != (g.rep); }
00553 HARD_TO_EXACT_IDENTITY_SUGAR(TMPL,Function)
00554 HARD_TO_TRUE_IDENTITY_SUGAR(TMPL,Function)
00555 TMPL inline bool is_nil (const Function& f) {
00556 return (void*) inside (f) == NULL; }
00557 #undef Function_rep
00558 #undef Function
00559 #undef TMPL
00560
00561
00562
00563
00564
00565 template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5, typename S6, typename S7, typename S8>
00566 struct function_8_rep REP_STRUCT {
00567 inline function_8_rep () {}
00568 virtual ~function_8_rep () {}
00569 virtual D apply (S1 x1, S2 x2, S3 x3, S4 x4, S5 x5, S6 x6, S7 x7, S8 x8) = 0;
00570 };
00571
00572 template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5, typename S6, typename S7, typename S8>
00573 struct def_function_8_rep: public function_8_rep<D,S1,S2,S3,S4,S5,S6,S7,S8> {
00574 D (*fun) (S1, S2, S3, S4, S5, S6, S7, S8);
00575 inline def_function_8_rep (D (*fun2) (S1, S2, S3, S4, S5, S6, S7, S8)):
00576 fun (fun2) {}
00577 D apply (S1 x1, S2 x2, S3 x3, S4 x4, S5 x5, S6 x6, S7 x7, S8 x8) {
00578 return fun (x1, x2, x3, x4, x5, x6, x7, x8); }
00579 };
00580
00581 template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5, typename S6, typename S7, typename S8>
00582 struct function_8 {
00583 function_8_rep<D,S1,S2,S3,S4,S5,S6,S7,S8>* rep;
00584 inline function_8 (): rep (NULL) {}
00585 inline function_8 (function_8_rep<D,S1,S2,S3,S4,S5,S6,S7,S8>* rep2): rep (rep2) {}
00586 inline function_8 (function_8_rep<D,S1,S2,S3,S4,S5,S6,S7,S8>* rep2,
00587 bool with_inc):
00588 rep (rep2) { (void) with_inc; INC_COUNT (rep); }
00589 inline function_8 (const function_8& f):
00590 rep (f.rep) { INC_NULL_COUNT(rep); }
00591 inline function_8 (D (*fun) (S1, S2, S3, S4, S5, S6, S7, S8)):
00592 rep (new def_function_8_rep<D,S1,S2,S3,S4,S5,S6,S7,S8> (fun)) {}
00593 inline ~function_8 () { DEC_NULL_COUNT (rep); }
00594 inline function_8& operator = (const function_8& f) {
00595 INC_NULL_COUNT (f.rep); DEC_NULL_COUNT (rep);
00596 rep= f.rep; return *this; }
00597 inline D operator () (S1 x1, S2 x2, S3 x3, S4 x4, S5 x5, S6 x6, S7 x7, S8 x8) const {
00598 return rep->apply (x1, x2, x3, x4, x5, x6, x7, x8); }
00599 };
00600
00601 #define TMPL template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5, typename S6, typename S7, typename S8>
00602 #define Function function_8<D,S1,S2,S3,S4,S5,S6,S7,S8>
00603 #define Function_rep function_8_rep<D,S1,S2,S3,S4,S5,S6,S7,S8>
00604 TMPL inline Function_rep* inside (const Function& f) { return f.rep; }
00605 TMPL inline syntactic flatten (const Function& f) {
00606 return "function"; }
00607 TMPL inline nat hard_hash (const Function& f) {
00608 return as_hash (f.rep); }
00609 TMPL inline bool hard_eq (const Function& f, const Function& g) {
00610 return (f.rep) == (g.rep); }
00611 TMPL inline bool hard_neq (const Function& f, const Function& g) {
00612 return (f.rep) != (g.rep); }
00613 HARD_TO_EXACT_IDENTITY_SUGAR(TMPL,Function)
00614 HARD_TO_TRUE_IDENTITY_SUGAR(TMPL,Function)
00615 TMPL inline bool is_nil (const Function& f) {
00616 return (void*) inside (f) == NULL; }
00617 #undef Function_rep
00618 #undef Function
00619 #undef TMPL
00620
00621 }
00622
00623 using namespace mmx;
00624 #endif // __MMX_FUNCTION_HPP