00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef MORE_GEN_CLOSURE_H
00032 #define MORE_GEN_CLOSURE_H
00033
00034 #include <more/gen/utility.h>
00035 #include <more/gen/functional.h>
00036
00037
00038 namespace more {
00039 namespace gen {
00040
00041
00042
00043 template <class Result>
00044 struct abstract_generator : generator<Result>, handle_data {
00045 abstract_generator() {}
00046 virtual ~abstract_generator() {}
00047 virtual Result operator()() = 0;
00048 };
00049
00050 template <class Arg, class Result>
00051 struct abstract_unary_function
00052 : unary_function<Arg, Result>, handle_data {
00053 abstract_unary_function() {}
00054 virtual ~abstract_unary_function() {}
00055 virtual Result operator()(Arg) = 0;
00056 };
00057
00058 template <class Arg1, class Arg2, class Result>
00059 struct abstract_binary_function
00060 : binary_function<Arg1, Arg2, Result>, handle_data {
00061 abstract_binary_function() {}
00062 virtual ~abstract_binary_function() {}
00063 virtual Result operator()(Arg1, Arg2) = 0;
00064 };
00065
00066 template <class Arg1, class Arg2, class Arg3, class Result>
00067 struct abstract_ternary_function
00068 : ternary_function<Arg1, Arg2, Arg3, Result>, handle_data {
00069 abstract_ternary_function() {}
00070 virtual ~abstract_ternary_function() {}
00071 virtual Result operator()(Arg1, Arg2, Arg3) = 0;
00072 };
00073
00074
00075
00076 template <class Result>
00077 struct const_abstract_generator : generator<Result>, handle_data {
00078 const_abstract_generator() {}
00079 virtual ~const_abstract_generator() {}
00080 virtual Result operator()() const = 0;
00081 };
00082
00083 template <class Arg, class Result>
00084 struct const_abstract_unary_function
00085 : unary_function<Arg, Result>, handle_data {
00086 const_abstract_unary_function() {}
00087 virtual ~const_abstract_unary_function() {}
00088 virtual Result operator()(Arg) const = 0;
00089 };
00090
00091 template <class Arg1, class Arg2, class Result>
00092 struct const_abstract_binary_function
00093 : binary_function<Arg1, Arg2, Result>, handle_data {
00094 const_abstract_binary_function() {}
00095 virtual ~const_abstract_binary_function() {}
00096 virtual Result operator()(Arg1, Arg2) const = 0;
00097 };
00098
00099 template <class Arg1, class Arg2, class Arg3, class Result>
00100 struct const_abstract_ternary_function
00101 : ternary_function<Arg1, Arg2, Arg3, Result>, handle_data {
00102 const_abstract_ternary_function() {}
00103 virtual ~const_abstract_ternary_function() {}
00104 virtual Result operator()(Arg1, Arg2, Arg3) const = 0;
00105 };
00106
00107
00108
00109
00110
00111 template<typename Generator>
00112 struct encapsulated_generator
00113 : abstract_generator< typename Generator::result_type > {
00114 typedef typename Generator::result_type result_type;
00115 result_type operator()() { return f(); }
00116 encapsulated_generator() {}
00117 encapsulated_generator(const Generator& f_) : f(f_) {}
00118 ~encapsulated_generator() {}
00119 private:
00120 Generator f;
00121 };
00122 template<typename UnaryFunction>
00123 struct encapsulated_unary_function
00124 : abstract_unary_function
00125 < typename UnaryFunction::argument_type,
00126 typename UnaryFunction::result_type > {
00127 typedef typename UnaryFunction::result_type result_type;
00128 typedef typename UnaryFunction::argument_type argument_type;
00129 result_type operator()(argument_type x) { return f(x); }
00130 encapsulated_unary_function() {}
00131 encapsulated_unary_function(const UnaryFunction& f_) : f(f_) {}
00132 ~encapsulated_unary_function() {}
00133 private:
00134 UnaryFunction f;
00135 };
00136 template<typename BinaryFunction>
00137 struct encapsulated_binary_function
00138 : abstract_binary_function
00139 < typename BinaryFunction::first_argument_type,
00140 typename BinaryFunction::second_argument_type,
00141 typename BinaryFunction::result_type > {
00142 typedef typename BinaryFunction::result_type result_type;
00143 typedef typename BinaryFunction::first_argument_type
00144 first_argument_type;
00145 typedef typename BinaryFunction::second_argument_type
00146 second_argument_type;
00147 result_type operator()(first_argument_type x,
00148 second_argument_type y) { return f(x, y); }
00149 encapsulated_binary_function() {}
00150 encapsulated_binary_function(const BinaryFunction& f_) : f(f_) {}
00151 ~encapsulated_binary_function() {}
00152 private:
00153 BinaryFunction f;
00154 };
00155 template<typename TernaryFunction>
00156 struct encapsulated_ternary_function
00157 : abstract_ternary_function
00158 < typename TernaryFunction::first_argument_type,
00159 typename TernaryFunction::second_argument_type,
00160 typename TernaryFunction::third_argument_type,
00161 typename TernaryFunction::result_type > {
00162 typedef typename TernaryFunction::result_type result_type;
00163 typedef typename TernaryFunction::first_argument_type
00164 first_argument_type;
00165 typedef typename TernaryFunction::second_argument_type
00166 second_argument_type;
00167 typedef typename TernaryFunction::third_argument_type
00168 third_argument_type;
00169 result_type operator()(first_argument_type x,
00170 second_argument_type y,
00171 third_argument_type z) { return f(x, y, z); }
00172 encapsulated_ternary_function() {}
00173 encapsulated_ternary_function(const TernaryFunction& f_) : f(f_) {}
00174 ~encapsulated_ternary_function() {}
00175 private:
00176 TernaryFunction f;
00177 };
00178
00179 template<typename Generator>
00180 struct const_encapsulated_generator
00181 : const_abstract_generator< typename Generator::result_type > {
00182 typedef typename Generator::result_type result_type;
00183 result_type operator()() { return f(); }
00184 const_encapsulated_generator() {}
00185 const_encapsulated_generator(const Generator& f_) : f(f_) {}
00186 ~const_encapsulated_generator() {}
00187 private:
00188 Generator f;
00189 };
00190 template<typename UnaryFunction>
00191 struct const_encapsulated_unary_function
00192 : const_abstract_unary_function
00193 < typename UnaryFunction::argument_type,
00194 typename UnaryFunction::result_type > {
00195 typedef typename UnaryFunction::result_type result_type;
00196 typedef typename UnaryFunction::argument_type argument_type;
00197 result_type operator()(argument_type x) const { return f(x); }
00198 const_encapsulated_unary_function() {}
00199 const_encapsulated_unary_function(const UnaryFunction& f_) : f(f_) {}
00200 private:
00201 UnaryFunction f;
00202 };
00203 template<typename BinaryFunction>
00204 struct const_encapsulated_binary_function
00205 : const_abstract_binary_function
00206 < typename BinaryFunction::first_argument_type,
00207 typename BinaryFunction::second_argument_type,
00208 typename BinaryFunction::result_type > {
00209 typedef typename BinaryFunction::result_type result_type;
00210 typedef typename BinaryFunction::first_argument_type
00211 first_argument_type;
00212 typedef typename BinaryFunction::second_argument_type
00213 second_argument_type;
00214 result_type operator()(first_argument_type x,
00215 second_argument_type y) const {
00216 return f(x, y);
00217 }
00218 const_encapsulated_binary_function() {}
00219 const_encapsulated_binary_function(const BinaryFunction& f_)
00220 : f(f_) {}
00221 ~const_encapsulated_binary_function() {}
00222 private:
00223 BinaryFunction f;
00224 };
00225 template<typename TernaryFunction>
00226 struct const_encapsulated_ternary_function
00227 : const_abstract_ternary_function
00228 < typename TernaryFunction::first_argument_type,
00229 typename TernaryFunction::second_argument_type,
00230 typename TernaryFunction::third_argument_type,
00231 typename TernaryFunction::result_type > {
00232 typedef typename TernaryFunction::result_type result_type;
00233 typedef typename TernaryFunction::first_argument_type
00234 first_argument_type;
00235 typedef typename TernaryFunction::second_argument_type
00236 second_argument_type;
00237 typedef typename TernaryFunction::third_argument_type
00238 third_argument_type;
00239 result_type operator()(first_argument_type x,
00240 second_argument_type y,
00241 third_argument_type z) const {
00242 return f(x, y, z);
00243 }
00244 const_encapsulated_ternary_function() {}
00245 const_encapsulated_ternary_function(const TernaryFunction& f_)
00246 : f(f_) {}
00247 ~const_encapsulated_ternary_function() {}
00248 private:
00249 TernaryFunction f;
00250 };
00251
00252
00253
00254 template<typename Generator>
00255 inline encapsulated_generator<Generator>*
00256 encapsulate_generator(const Generator& f) {
00257 return new encapsulated_generator<Generator>(f);
00258 }
00259
00260 template<typename UnaryFunction>
00261 inline encapsulated_unary_function<UnaryFunction>*
00262 encapsulate_unary(const UnaryFunction& f) {
00263 return new encapsulated_unary_function<UnaryFunction>(f);
00264 }
00265
00266 template<typename BinaryFunction>
00267 inline encapsulated_binary_function<BinaryFunction>*
00268 encapsulate_binary(const BinaryFunction& f) {
00269 return new encapsulated_binary_function<BinaryFunction>(f);
00270 }
00271
00272 template<typename TernaryFunction>
00273 inline encapsulated_ternary_function<TernaryFunction>*
00274 encapsulate_ternary(const TernaryFunction& f) {
00275 return new encapsulated_ternary_function<TernaryFunction>(f);
00276 }
00277
00278
00279 template<typename Generator>
00280 inline const_encapsulated_generator<Generator>*
00281 const_encapsulate_generator(const Generator& f) {
00282 return new const_encapsulated_generator<Generator>(f);
00283 }
00284
00285 template<typename UnaryFunction>
00286 inline const_encapsulated_unary_function<UnaryFunction>*
00287 const_encapsulate_unary(const UnaryFunction& f) {
00288 return new const_encapsulated_unary_function<UnaryFunction>(f);
00289 }
00290
00291 template<typename BinaryFunction>
00292 inline const_encapsulated_binary_function<BinaryFunction>*
00293 const_encapsulate_binary(const BinaryFunction& f) {
00294 return new const_encapsulated_binary_function<BinaryFunction>(f);
00295 }
00296
00297 template<typename TernaryFunction>
00298 inline const_encapsulated_ternary_function<TernaryFunction>*
00299 const_encapsulate_ternary(const TernaryFunction& f) {
00300 return new const_encapsulated_ternary_function<TernaryFunction>(f);
00301 }
00302
00303
00304
00305
00306
00307 template<typename Result>
00308 class generator_closure : public generator<Result> {
00309 typedef generator<Result> base;
00310
00311 public:
00312 typedef typename base::result_type result_type;
00313
00314 generator_closure() : f(encapsulate_generator(adapt(undef))) {}
00315 generator_closure(generator_closure const& x) : f(x.f) {}
00316 generator_closure&
00317 operator=(generator_closure const& x) {
00318 f = x.f;
00319 return *this;
00320 }
00321
00322 template<typename Generator>
00323 generator_closure(const Generator& f_)
00324 : f(new encapsulated_generator<Generator>(f_)) {}
00325 template<typename Generator>
00326 generator_closure&
00327 operator=(const Generator& f_) {
00328 f.set_data(new encapsulated_generator<Generator>(f_));
00329 return *this;
00330 }
00331
00332 generator_closure(Result (*f_)())
00333 : f(encapsulate_generator(adapt(f_))) {}
00334 generator_closure&
00335 operator=(Result (*f_)()) {
00336 f.set_data(encapsulate_generator(adapt(f_)));
00337 return *this;
00338 }
00339
00340 result_type operator()() { return (*f.data())(); }
00341 private:
00342 handle< abstract_generator<Result> > f;
00343
00344 static Result undef() {
00345 throw std::logic_error("more::gen::generator_closure: "
00346 "Undefined closure.");
00347 }
00348 };
00349
00350 template<typename Arg, typename Result>
00351 class unary_closure : public unary_function<Arg, Result> {
00352 typedef unary_function<Arg, Result> base;
00353
00354 public:
00355 typedef typename base::argument_type argument_type;
00356 typedef typename base::result_type result_type;
00357
00358 unary_closure() : f(encapsulate_unary(adapt(undef))) {}
00359 unary_closure(unary_closure const& x) : f(x.f) {}
00360 unary_closure&
00361 operator=(unary_closure const& x) {
00362 f = x.f;
00363 return *this;
00364 }
00365
00366 template<typename UnaryFunction>
00367 unary_closure(const UnaryFunction& f_)
00368 : f(new encapsulated_unary_function<UnaryFunction>(f_)) {}
00369 template<typename UnaryFunction>
00370 unary_closure&
00371 operator=(UnaryFunction& f_) {
00372 f.set_data(new encapsulated_unary_function<UnaryFunction>(f_));
00373 return *this;
00374 }
00375
00376 unary_closure(Result (*f_)(Arg))
00377 : f(encapsulate_unary(adapt(f_))) {}
00378 unary_closure&
00379 operator=(Result (*f_)(Arg)) {
00380 f.set_data(encapsulate_unary(adapt(f_)));
00381 return *this;
00382 }
00383
00384 result_type operator()(argument_type x) {
00385 return (*f.data())(x);
00386 }
00387 private:
00388 handle< abstract_unary_function<Arg, Result> > f;
00389
00390 static Result undef(Arg) {
00391 throw std::logic_error("more::gen::unary_closure: "
00392 "Undefined closure.");
00393 }
00394 };
00395
00396 template<typename Arg1, typename Arg2, typename Result>
00397 class binary_closure : public binary_function<Arg1, Arg2, Result> {
00398 typedef binary_function<Arg1, Arg2, Result> base;
00399
00400 public:
00401 typedef typename base::first_argument_type first_argument_type;
00402 typedef typename base::second_argument_type second_argument_type;
00403 typedef typename base::result_type result_type;
00404
00405 binary_closure() : f(encapsulate_binary(adapt(undef))) {}
00406 binary_closure(binary_closure const& x) : f(x.f) {}
00407 binary_closure&
00408 operator=(binary_closure const& x) {
00409 f = x.f;
00410 return *this;
00411 }
00412
00413 template<typename BinaryFunction>
00414 binary_closure(const BinaryFunction& f_)
00415 : f(new encapsulated_binary_function<BinaryFunction>(f_)) {}
00416 template<typename BinaryFunction>
00417 binary_closure&
00418 operator=(const BinaryFunction& f_) {
00419 f.set_data(new encapsulated_binary_function
00420 <BinaryFunction>(f_));
00421 return *this;
00422 }
00423
00424 binary_closure(Result (*f_)(Arg1, Arg2))
00425 : f(encapsulate_binary(adapt(f_))) {}
00426 binary_closure&
00427 operator=(Result (*f_)(Arg1, Arg2)) {
00428 f.set_data(encapsulate_binary(adapt(f_)));
00429 return *this;
00430 }
00431
00432 result_type
00433 operator()(first_argument_type x, second_argument_type y) {
00434 return (*f.data())(x, y);
00435 }
00436
00437 private:
00438 handle< abstract_binary_function<Arg1, Arg2, Result> > f;
00439
00440 static Result undef(Arg1, Arg2) {
00441 throw std::logic_error("more::gen::generator_closure: "
00442 "Undefined closure.");
00443 }
00444 };
00445
00446 template<typename Arg1, typename Arg2, typename Arg3, typename Result>
00447 class ternary_closure
00448 : public ternary_function<Arg1, Arg2, Arg3, Result> {
00449 typedef ternary_function<Arg1, Arg2, Arg3, Result> base;
00450
00451 public:
00452 typedef typename base::first_argument_type first_argument_type;
00453 typedef typename base::second_argument_type second_argument_type;
00454 typedef typename base::third_argument_type third_argument_type;
00455 typedef typename base::result_type result_type;
00456
00457 ternary_closure() : f(encapsulate_ternary(adapt(undef))) {}
00458 ternary_closure(ternary_closure const& x) : f(x.f) {}
00459 ternary_closure&
00460 operator=(ternary_closure const& x) {
00461 f = x.f;
00462 return *this;
00463 }
00464
00465 template<typename TernaryFunction>
00466 ternary_closure(const TernaryFunction& f_)
00467 : f(new encapsulated_ternary_function<TernaryFunction>(f_)) {}
00468 template<typename TernaryFunction>
00469 ternary_closure&
00470 operator=(TernaryFunction const& f_) {
00471 f.set_data(new encapsulated_ternary_function
00472 <TernaryFunction>(f_));
00473 return *this;
00474 }
00475
00476 ternary_closure(Result (*f_)(Arg1, Arg2, Arg3))
00477 : f(encapsulate_ternary(adapt(f_))) {}
00478 ternary_closure&
00479 operator=(Result (*f_)(Arg1, Arg2, Arg3)) {
00480 f.set_data(encapsulate_ternary(adapt(f_)));
00481 return *this;
00482 }
00483
00484 result_type
00485 operator()(first_argument_type x, second_argument_type y,
00486 third_argument_type z) {
00487 return (*f.data())(x, y, z);
00488 }
00489 private:
00490 handle< abstract_ternary_function<Arg1, Arg2, Arg3, Result> > f;
00491
00492 static Result undef(Arg1, Arg2, Arg3) {
00493 throw std::logic_error("more::gen::generator_closure: "
00494 "Undefined closure.");
00495 }
00496 };
00497
00498
00499
00500 template<typename Result>
00501 class const_generator_closure : public generator<Result> {
00502 typedef generator<Result> base;
00503
00504 public:
00505 typedef typename base::result_type result_type;
00506
00507 const_generator_closure()
00508 : f(const_encapsulate_generator(adapt(undef))) {}
00509 const_generator_closure(const_generator_closure const& x)
00510 : f(x.f) {}
00511 const_generator_closure&
00512 operator=(const_generator_closure const& x) {
00513 f = x.f;
00514 return *this;
00515 }
00516
00517 template<typename Generator>
00518 const_generator_closure(const Generator& f_)
00519 : f(new const_encapsulated_generator<Generator>(f_)) {}
00520 template<typename Generator>
00521 const_generator_closure& operator=(const Generator& f_) {
00522 f.set_data(new const_encapsulated_generator<Generator>(f_));
00523 return *this;
00524 }
00525
00526 const_generator_closure(Result (*f_)())
00527 : f(const_encapsulate_generator(adapt(f_))) {}
00528 const_generator_closure&
00529 operator=(Result (*f_)()) {
00530 f.set_data(const_encapsulate_generator(adapt(f_)));
00531 return *this;
00532 }
00533
00534 result_type
00535 operator()() const { return (*f.data())(); }
00536
00537 private:
00538 handle< const_abstract_generator<Result> > f;
00539
00540 static Result undef() {
00541 throw std::logic_error("more::gen::generator_closure: "
00542 "Undefined closure.");
00543 }
00544 };
00545
00546 template<typename Arg, typename Result>
00547 class const_unary_closure : public unary_function<Arg, Result> {
00548 typedef unary_function<Arg, Result> base;
00549
00550 public:
00551 typedef typename base::argument_type argument_type;
00552 typedef typename base::result_type result_type;
00553
00554 const_unary_closure()
00555 : f(const_encapsulate_unary(adapt(undef))) {}
00556 const_unary_closure(const_unary_closure const& x) : f(x.f) {}
00557 const_unary_closure& operator=(const_unary_closure const& x) {
00558 f = x.f;
00559 return *this;
00560 }
00561
00562 template<typename UnaryFunction>
00563 const_unary_closure(const UnaryFunction& f_)
00564 : f(new const_encapsulated_unary_function<UnaryFunction>(f_)) {}
00565 template<typename UnaryFunction>
00566 const_unary_closure&
00567 operator=(const UnaryFunction& f_) {
00568 f.set_data(new const_encapsulated_unary_function
00569 <UnaryFunction>(f_));
00570 return *this;
00571 }
00572
00573 const_unary_closure(Result (*f_)(Arg))
00574 : f(const_encapsulate_unary(adapt(f_))) {}
00575 const_unary_closure&
00576 operator=(Result (*f_)(Arg)) {
00577 f.set_data(const_encapsulate_unary(adapt(f_)));
00578 return *this;
00579 }
00580
00581 result_type
00582 operator()(argument_type x) const { return (*f.data())(x); }
00583
00584 private:
00585 handle< const_abstract_unary_function<Arg, Result> > f;
00586
00587 static Result undef(Arg) {
00588 throw std::logic_error("more::gen::generator_closure: "
00589 "Undefined closure.");
00590 }
00591 };
00592
00593 template<typename Arg1, typename Arg2, typename Result>
00594 class const_binary_closure
00595 : public binary_function<Arg1, Arg2, Result> {
00596 typedef binary_function<Arg1, Arg2, Result> base;
00597
00598 public:
00599 typedef typename base::first_argument_type first_argument_type;
00600 typedef typename base::second_argument_type second_argument_type;
00601 typedef typename base::result_type result_type;
00602
00603 const_binary_closure()
00604 : f(const_encapsulate_binary(adapt(undef))) {}
00605 const_binary_closure(const_binary_closure const& x) : f(x.f) {}
00606 const_binary_closure&
00607 operator=(const_binary_closure const& x) {
00608 f = x.f;
00609 return *this;
00610 }
00611
00612 template<typename BinaryFunction>
00613 const_binary_closure(const BinaryFunction& f_)
00614 : f(new const_encapsulated_binary_function
00615 <BinaryFunction>(f_)) {}
00616 template<typename BinaryFunction>
00617 const_binary_closure&
00618 operator=(const BinaryFunction& f_) {
00619 f.set_data(new const_encapsulated_binary_function
00620 <BinaryFunction>(f_));
00621 return *this;
00622 }
00623
00624 const_binary_closure(Result (*f_)(Arg1, Arg2))
00625 : f(const_encapsulate_binary(adapt(f_))) {}
00626 const_binary_closure&
00627 operator=(Result (*f_)(Arg1, Arg2)) {
00628 f.set_data(const_encapsulate_binary(adapt(f_)));
00629 return *this;
00630 }
00631
00632 result_type
00633 operator()(first_argument_type x, second_argument_type y) const {
00634 return (*f.data())(x, y);
00635 }
00636
00637 private:
00638 handle< const_abstract_binary_function<Arg1, Arg2, Result> > f;
00639
00640 static Result undef(Arg1, Arg2) {
00641 throw std::logic_error("more::gen::generator_closure: "
00642 "Undefined closure.");
00643 }
00644 };
00645
00646 template<typename Arg1, typename Arg2, typename Arg3, typename Result>
00647 class const_ternary_closure
00648 : public ternary_function<Arg1, Arg2, Arg3, Result> {
00649 typedef ternary_function<Arg1, Arg2, Arg3, Result> base;
00650
00651 public:
00652 typedef typename base::first_argument_type first_argument_type;
00653 typedef typename base::second_argument_type second_argument_type;
00654 typedef typename base::third_argument_type third_argument_type;
00655 typedef typename base::result_type result_type;
00656
00657 const_ternary_closure()
00658 : f(const_encapsulate_ternary(adapt(undef))) {}
00659 const_ternary_closure(const_ternary_closure const& x) : f(x.f) {}
00660 const_ternary_closure&
00661 operator=(const_ternary_closure const& x) {
00662 f = x.f;
00663 return *this;
00664 }
00665
00666 template<typename TernaryFunction>
00667 const_ternary_closure(const TernaryFunction& f_)
00668 : f(new const_encapsulated_ternary_function
00669 <TernaryFunction>(f_)) {}
00670 template<typename TernaryFunction>
00671 const_ternary_closure&
00672 operator=(const TernaryFunction& f) {
00673 f.set_data(new const_encapsulated_ternary_function
00674 <TernaryFunction>(f_));
00675 return *this;
00676 }
00677
00678 const_ternary_closure(Result (*f_)(Arg1, Arg2, Arg3))
00679 : f(const_encapsulate_ternary(adapt(f_))) {}
00680 const_ternary_closure&
00681 operator=(Result (*f_)(Arg1, Arg2, Arg3)) {
00682 f.set_data(const_encapsulate_ternary(adapt(f_)));
00683 return *this;
00684 }
00685
00686 result_type
00687 operator()(first_argument_type x, second_argument_type y,
00688 third_argument_type z) const {
00689 return (*f.data())(x, y, z);
00690 }
00691
00692 private:
00693 handle< const_abstract_ternary_function<Arg1, Arg2, Arg3, Result> > f;
00694
00695 static Result undef(Arg1, Arg2, Arg3) {
00696 throw std::logic_error("more::gen::generator_closure: "
00697 "Undefined closure.");
00698 }
00699 };
00700
00701
00702
00703
00704
00705
00706
00707 template<typename Res>
00708 inline void connect(generator_closure<Res>& slot, Res (*f)()) {
00709 slot = generator_closure<Res>(adapt(f));
00710 }
00711 template<typename Arg, typename Res>
00712 inline void connect(unary_closure<Arg, Res>& slot, Res (*f)(Arg)) {
00713 slot = unary_closure<Arg, Res>(adapt(f));
00714 }
00715 template<typename Arg1, typename Arg2, typename Res>
00716 inline void connect(binary_closure<Arg1, Arg2, Res>& slot,
00717 Res (*f)(Arg1, Arg2)) {
00718 slot = binary_closure<Arg1, Arg2, Res>(adapt(f));
00719 }
00720 template<typename Arg1, typename Arg2, typename Arg3, typename Res>
00721 inline void connect(ternary_closure<Arg1, Arg2, Arg3, Res>& slot,
00722 Res (*f)(Arg1, Arg2, Arg3)) {
00723 slot = ternary_closure<Arg1, Arg2, Arg3, Res>(adapt(f));
00724 }
00725
00726
00727 template<typename Obj, typename Res>
00728 inline void connect(unary_closure<Obj&, Res>& slot,
00729 Res (Obj::*f)()) {
00730 slot = unary_closure<Obj&, Res>(adapt(f));
00731 }
00732 template<typename Obj, typename Arg, typename Res>
00733 inline void connect(binary_closure<Obj&, Arg, Res>& slot,
00734 Res (Obj::*f)(Arg)) {
00735 slot = binary_closure<Obj&, Arg, Res>(adapt(f));
00736 }
00737 template<typename Obj, typename Arg1, typename Arg2, typename Res>
00738 inline void connect(ternary_closure<Obj&, Arg1, Arg2, Res>& slot,
00739 Res (Obj::*f)(Arg1, Arg2)) {
00740 slot = ternary_closure<Obj&, Arg1, Arg2, Res>(adapt(f));
00741 }
00742
00743
00744 template<typename Res, typename Obj>
00745 inline void connect(generator_closure<Res>& slot,
00746 Obj& obj, Res (Obj::*f)()) {
00747 slot = generator_closure<Res>(bind_adapt(&obj, f));
00748 }
00749 template<typename Res, typename Arg, typename Obj>
00750 inline void connect(unary_closure<Arg, Res>& slot,
00751 Obj& obj, Res (Obj::*f)(Arg)) {
00752 slot = unary_closure<Arg, Res>(bind_adapt(&obj, f));
00753 }
00754 template<typename Res, typename Arg1, typename Arg2, typename Obj>
00755 inline void connect(binary_closure<Arg1, Arg2, Res>& slot,
00756 Obj& obj, Res (Obj::*f)(Arg1, Arg2)) {
00757 slot = binary_closure<Arg1, Arg2, Res>(bind_adapt(&obj, f));
00758 }
00759 template< typename Res, typename Arg1, typename Arg2, typename Arg3,
00760 typename Obj >
00761 inline void connect(ternary_closure<Arg1, Arg2, Arg3, Res>& slot,
00762 Obj& obj, Res (Obj::*f)(Arg1, Arg2, Arg3)) {
00763 slot = ternary_closure<Arg1, Arg2, Arg3, Res>(bind_adapt(&obj, f));
00764 }
00765
00766 }}
00767
00768
00769 #endif