File indexing completed on 2025-01-18 09:39:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #if !defined(BOOST_LAMBDA_LOOPS_HPP)
0016 #define BOOST_LAMBDA_LOOPS_HPP
0017
0018 #include "boost/lambda/core.hpp"
0019
0020 namespace boost {
0021 namespace lambda {
0022
0023
0024
0025 class forloop_action {};
0026 class forloop_no_body_action {};
0027 class whileloop_action {};
0028 class whileloop_no_body_action {};
0029 class dowhileloop_action {};
0030 class dowhileloop_no_body_action {};
0031
0032
0033
0034 template <class Arg1, class Arg2, class Arg3, class Arg4>
0035 inline const
0036 lambda_functor<
0037 lambda_functor_base<
0038 forloop_action,
0039 tuple<lambda_functor<Arg1>, lambda_functor<Arg2>,
0040 lambda_functor<Arg3>, lambda_functor<Arg4> >
0041 >
0042 >
0043 for_loop(const lambda_functor<Arg1>& a1, const lambda_functor<Arg2>& a2,
0044 const lambda_functor<Arg3>& a3, const lambda_functor<Arg4>& a4) {
0045 return
0046 lambda_functor_base<
0047 forloop_action,
0048 tuple<lambda_functor<Arg1>, lambda_functor<Arg2>,
0049 lambda_functor<Arg3>, lambda_functor<Arg4> >
0050 >
0051 ( tuple<lambda_functor<Arg1>, lambda_functor<Arg2>,
0052 lambda_functor<Arg3>, lambda_functor<Arg4> >(a1, a2, a3, a4)
0053 );
0054 }
0055
0056
0057 template <class Arg1, class Arg2, class Arg3>
0058 inline const
0059 lambda_functor<
0060 lambda_functor_base<
0061 forloop_no_body_action,
0062 tuple<lambda_functor<Arg1>, lambda_functor<Arg2>, lambda_functor<Arg3> >
0063 >
0064 >
0065 for_loop(const lambda_functor<Arg1>& a1, const lambda_functor<Arg2>& a2,
0066 const lambda_functor<Arg3>& a3) {
0067 return
0068 lambda_functor_base<
0069 forloop_no_body_action,
0070 tuple<lambda_functor<Arg1>, lambda_functor<Arg2>,
0071 lambda_functor<Arg3> >
0072 >
0073 ( tuple<lambda_functor<Arg1>, lambda_functor<Arg2>,
0074 lambda_functor<Arg3> >(a1, a2, a3) );
0075 }
0076
0077
0078 template <class Arg1, class Arg2>
0079 inline const
0080 lambda_functor<
0081 lambda_functor_base<
0082 whileloop_action,
0083 tuple<lambda_functor<Arg1>, lambda_functor<Arg2> >
0084 >
0085 >
0086 while_loop(const lambda_functor<Arg1>& a1, const lambda_functor<Arg2>& a2) {
0087 return
0088 lambda_functor_base<
0089 whileloop_action,
0090 tuple<lambda_functor<Arg1>, lambda_functor<Arg2> >
0091 >
0092 ( tuple<lambda_functor<Arg1>, lambda_functor<Arg2> >(a1, a2));
0093 }
0094
0095
0096 template <class Arg1>
0097 inline const
0098 lambda_functor<
0099 lambda_functor_base<
0100 whileloop_no_body_action,
0101 tuple<lambda_functor<Arg1> >
0102 >
0103 >
0104 while_loop(const lambda_functor<Arg1>& a1) {
0105 return
0106 lambda_functor_base<
0107 whileloop_no_body_action,
0108 tuple<lambda_functor<Arg1> >
0109 >
0110 ( tuple<lambda_functor<Arg1> >(a1) );
0111 }
0112
0113
0114
0115 template <class Arg1, class Arg2>
0116 inline const
0117 lambda_functor<
0118 lambda_functor_base<
0119 dowhileloop_action,
0120 tuple<lambda_functor<Arg1>, lambda_functor<Arg2> >
0121 >
0122 >
0123 do_while_loop(const lambda_functor<Arg1>& a1, const lambda_functor<Arg2>& a2) {
0124 return
0125 lambda_functor_base<
0126 dowhileloop_action,
0127 tuple<lambda_functor<Arg1>, lambda_functor<Arg2> >
0128 >
0129 ( tuple<lambda_functor<Arg1>, lambda_functor<Arg2> >(a1, a2));
0130 }
0131
0132
0133 template <class Arg1>
0134 inline const
0135 lambda_functor<
0136 lambda_functor_base<
0137 dowhileloop_no_body_action,
0138 tuple<lambda_functor<Arg1> >
0139 >
0140 >
0141 do_while_loop(const lambda_functor<Arg1>& a1) {
0142 return
0143 lambda_functor_base<
0144 dowhileloop_no_body_action,
0145 tuple<lambda_functor<Arg1> >
0146 >
0147 ( tuple<lambda_functor<Arg1> >(a1));
0148 }
0149
0150
0151
0152
0153
0154 template<class Args>
0155 class
0156 lambda_functor_base<forloop_action, Args> {
0157 public:
0158 Args args;
0159 template <class T> struct sig { typedef void type; };
0160 public:
0161 explicit lambda_functor_base(const Args& a) : args(a) {}
0162
0163 template<class RET, CALL_TEMPLATE_ARGS>
0164 RET call(CALL_FORMAL_ARGS) const {
0165 for(detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS);
0166 detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS);
0167 detail::select(boost::tuples::get<2>(args), CALL_ACTUAL_ARGS))
0168
0169 detail::select(boost::tuples::get<3>(args), CALL_ACTUAL_ARGS);
0170 }
0171 };
0172
0173
0174 template<class Args>
0175 class
0176 lambda_functor_base<forloop_no_body_action, Args> {
0177 public:
0178 Args args;
0179 template <class T> struct sig { typedef void type; };
0180 public:
0181 explicit lambda_functor_base(const Args& a) : args(a) {}
0182
0183 template<class RET, CALL_TEMPLATE_ARGS>
0184 RET call(CALL_FORMAL_ARGS) const {
0185 for(detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS);
0186 detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS);
0187 detail::select(boost::tuples::get<2>(args), CALL_ACTUAL_ARGS)) {}
0188 }
0189 };
0190
0191
0192
0193 template<class Args>
0194 class
0195 lambda_functor_base<whileloop_action, Args> {
0196 public:
0197 Args args;
0198 template <class T> struct sig { typedef void type; };
0199 public:
0200 explicit lambda_functor_base(const Args& a) : args(a) {}
0201
0202 template<class RET, CALL_TEMPLATE_ARGS>
0203 RET call(CALL_FORMAL_ARGS) const {
0204 while(detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS))
0205
0206 detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS);
0207 }
0208 };
0209
0210
0211 template<class Args>
0212 class
0213 lambda_functor_base<whileloop_no_body_action, Args> {
0214 public:
0215 Args args;
0216 template <class T> struct sig { typedef void type; };
0217 public:
0218 explicit lambda_functor_base(const Args& a) : args(a) {}
0219
0220 template<class RET, CALL_TEMPLATE_ARGS>
0221 RET call(CALL_FORMAL_ARGS) const {
0222 while(detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS)) {}
0223 }
0224 };
0225
0226
0227
0228 template<class Args>
0229 class
0230 lambda_functor_base<dowhileloop_action, Args> {
0231 public:
0232 Args args;
0233 template <class T> struct sig { typedef void type; };
0234 public:
0235 explicit lambda_functor_base(const Args& a) : args(a) {}
0236
0237 template<class RET, CALL_TEMPLATE_ARGS>
0238 RET call(CALL_FORMAL_ARGS) const {
0239 do {
0240 detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS);
0241 } while (detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS) );
0242 }
0243 };
0244
0245
0246 template<class Args>
0247 class
0248 lambda_functor_base<dowhileloop_no_body_action, Args> {
0249 public:
0250 Args args;
0251 template <class T> struct sig { typedef void type; };
0252 public:
0253 explicit lambda_functor_base(const Args& a) : args(a) {}
0254
0255 template<class RET, CALL_TEMPLATE_ARGS>
0256 RET call(CALL_FORMAL_ARGS) const {
0257 do {} while (detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS) );
0258 }
0259 };
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280 template <typename CondT, typename DoT>
0281 struct while_composite {
0282
0283 typedef while_composite<CondT, DoT> self_t;
0284
0285 template <class SigArgs>
0286 struct sig { typedef void type; };
0287
0288 while_composite(CondT const& cond_, DoT const& do__)
0289 : cond(cond_), do_(do__) {}
0290
0291 template <class Ret, CALL_TEMPLATE_ARGS>
0292 Ret call(CALL_FORMAL_ARGS) const
0293 {
0294 while (cond.internal_call(CALL_ACTUAL_ARGS))
0295 do_.internal_call(CALL_ACTUAL_ARGS);
0296 }
0297
0298 CondT cond;
0299 DoT do_;
0300 };
0301
0302
0303 template <typename CondT>
0304 struct while_gen {
0305
0306 while_gen(CondT const& cond_)
0307 : cond(cond_) {}
0308
0309 template <typename DoT>
0310 lambda_functor<while_composite<
0311 typename as_lambda_functor<CondT>::type,
0312 typename as_lambda_functor<DoT>::type> >
0313 operator[](DoT const& do_) const
0314 {
0315 typedef while_composite<
0316 typename as_lambda_functor<CondT>::type,
0317 typename as_lambda_functor<DoT>::type>
0318 result;
0319
0320 return result(
0321 to_lambda_functor(cond),
0322 to_lambda_functor(do_));
0323 }
0324
0325 CondT cond;
0326 };
0327
0328
0329 template <typename CondT>
0330 inline while_gen<CondT>
0331 while_(CondT const& cond)
0332 {
0333 return while_gen<CondT>(cond);
0334 }
0335
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355 template <typename DoT, typename CondT>
0356 struct do_composite {
0357
0358 typedef do_composite<DoT, CondT> self_t;
0359
0360 template <class SigArgs>
0361 struct sig { typedef void type; };
0362
0363 do_composite(DoT const& do__, CondT const& cond_)
0364 : do_(do__), cond(cond_) {}
0365
0366 template <class Ret, CALL_TEMPLATE_ARGS>
0367 Ret call(CALL_FORMAL_ARGS) const
0368 {
0369 do
0370 do_.internal_call(CALL_ACTUAL_ARGS);
0371 while (cond.internal_call(CALL_ACTUAL_ARGS));
0372 }
0373
0374 DoT do_;
0375 CondT cond;
0376 };
0377
0378
0379 template <typename DoT>
0380 struct do_gen2 {
0381
0382 do_gen2(DoT const& do__)
0383 : do_(do__) {}
0384
0385 template <typename CondT>
0386 lambda_functor<do_composite<
0387 typename as_lambda_functor<DoT>::type,
0388 typename as_lambda_functor<CondT>::type> >
0389 while_(CondT const& cond) const
0390 {
0391 typedef do_composite<
0392 typename as_lambda_functor<DoT>::type,
0393 typename as_lambda_functor<CondT>::type>
0394 result;
0395
0396 return result(
0397 to_lambda_functor(do_),
0398 to_lambda_functor(cond));
0399 }
0400
0401 DoT do_;
0402 };
0403
0404
0405 struct do_gen {
0406
0407 template <typename DoT>
0408 do_gen2<DoT>
0409 operator[](DoT const& do_) const
0410 {
0411 return do_gen2<DoT>(do_);
0412 }
0413 };
0414
0415 do_gen const do_ = do_gen();
0416
0417
0418
0419
0420
0421
0422
0423
0424
0425
0426
0427
0428
0429
0430
0431
0432
0433
0434
0435 template <typename InitT, typename CondT, typename StepT, typename DoT>
0436 struct for_composite {
0437
0438 template <class SigArgs>
0439 struct sig { typedef void type; };
0440
0441 for_composite(
0442 InitT const& init_,
0443 CondT const& cond_,
0444 StepT const& step_,
0445 DoT const& do__)
0446 : init(init_), cond(cond_), step(step_), do_(do__) {}
0447
0448 template <class Ret, CALL_TEMPLATE_ARGS>
0449 Ret
0450 call(CALL_FORMAL_ARGS) const
0451 {
0452 for (init.internal_call(CALL_ACTUAL_ARGS); cond.internal_call(CALL_ACTUAL_ARGS); step.internal_call(CALL_ACTUAL_ARGS))
0453 do_.internal_call(CALL_ACTUAL_ARGS);
0454 }
0455
0456 InitT init; CondT cond; StepT step; DoT do_;
0457 };
0458
0459
0460 template <typename InitT, typename CondT, typename StepT>
0461 struct for_gen {
0462
0463 for_gen(
0464 InitT const& init_,
0465 CondT const& cond_,
0466 StepT const& step_)
0467 : init(init_), cond(cond_), step(step_) {}
0468
0469 template <typename DoT>
0470 lambda_functor<for_composite<
0471 typename as_lambda_functor<InitT>::type,
0472 typename as_lambda_functor<CondT>::type,
0473 typename as_lambda_functor<StepT>::type,
0474 typename as_lambda_functor<DoT>::type> >
0475 operator[](DoT const& do_) const
0476 {
0477 typedef for_composite<
0478 typename as_lambda_functor<InitT>::type,
0479 typename as_lambda_functor<CondT>::type,
0480 typename as_lambda_functor<StepT>::type,
0481 typename as_lambda_functor<DoT>::type>
0482 result;
0483
0484 return result(
0485 to_lambda_functor(init),
0486 to_lambda_functor(cond),
0487 to_lambda_functor(step),
0488 to_lambda_functor(do_));
0489 }
0490
0491 InitT init; CondT cond; StepT step;
0492 };
0493
0494
0495 template <typename InitT, typename CondT, typename StepT>
0496 inline for_gen<InitT, CondT, StepT>
0497 for_(InitT const& init, CondT const& cond, StepT const& step)
0498 {
0499 return for_gen<InitT, CondT, StepT>(init, cond, step);
0500 }
0501
0502 }
0503 }
0504
0505 #endif