1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/lambda/loops.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,505 @@
1.4 +// Boost Lambda Library -- loops.hpp ----------------------------------------
1.5 +
1.6 +// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
1.7 +// Copyright (C) 2000 Gary Powell (powellg@amazon.com)
1.8 +// Copyright (c) 2001-2002 Joel de Guzman
1.9 +//
1.10 +// Distributed under the Boost Software License, Version 1.0. (See
1.11 +// accompanying file LICENSE_1_0.txt or copy at
1.12 +// http://www.boost.org/LICENSE_1_0.txt)
1.13 +//
1.14 +// For more information, see www.boost.org
1.15 +
1.16 +// --------------------------------------------------------------------------
1.17 +
1.18 +#if !defined(BOOST_LAMBDA_LOOPS_HPP)
1.19 +#define BOOST_LAMBDA_LOOPS_HPP
1.20 +
1.21 +#include "boost/lambda/core.hpp"
1.22 +
1.23 +namespace boost {
1.24 +namespace lambda {
1.25 +
1.26 +// -- loop control structure actions ----------------------
1.27 +
1.28 +class forloop_action {};
1.29 +class forloop_no_body_action {};
1.30 +class whileloop_action {};
1.31 +class whileloop_no_body_action {};
1.32 +class dowhileloop_action {};
1.33 +class dowhileloop_no_body_action {};
1.34 +
1.35 +
1.36 +// For loop
1.37 +template <class Arg1, class Arg2, class Arg3, class Arg4>
1.38 +inline const
1.39 +lambda_functor<
1.40 + lambda_functor_base<
1.41 + forloop_action,
1.42 + tuple<lambda_functor<Arg1>, lambda_functor<Arg2>,
1.43 + lambda_functor<Arg3>, lambda_functor<Arg4> >
1.44 + >
1.45 +>
1.46 +for_loop(const lambda_functor<Arg1>& a1, const lambda_functor<Arg2>& a2,
1.47 + const lambda_functor<Arg3>& a3, const lambda_functor<Arg4>& a4) {
1.48 + return
1.49 + lambda_functor_base<
1.50 + forloop_action,
1.51 + tuple<lambda_functor<Arg1>, lambda_functor<Arg2>,
1.52 + lambda_functor<Arg3>, lambda_functor<Arg4> >
1.53 + >
1.54 + ( tuple<lambda_functor<Arg1>, lambda_functor<Arg2>,
1.55 + lambda_functor<Arg3>, lambda_functor<Arg4> >(a1, a2, a3, a4)
1.56 + );
1.57 +}
1.58 +
1.59 +// No body case.
1.60 +template <class Arg1, class Arg2, class Arg3>
1.61 +inline const
1.62 +lambda_functor<
1.63 + lambda_functor_base<
1.64 + forloop_no_body_action,
1.65 + tuple<lambda_functor<Arg1>, lambda_functor<Arg2>, lambda_functor<Arg3> >
1.66 + >
1.67 +>
1.68 +for_loop(const lambda_functor<Arg1>& a1, const lambda_functor<Arg2>& a2,
1.69 + const lambda_functor<Arg3>& a3) {
1.70 + return
1.71 + lambda_functor_base<
1.72 + forloop_no_body_action,
1.73 + tuple<lambda_functor<Arg1>, lambda_functor<Arg2>,
1.74 + lambda_functor<Arg3> >
1.75 + >
1.76 + ( tuple<lambda_functor<Arg1>, lambda_functor<Arg2>,
1.77 + lambda_functor<Arg3> >(a1, a2, a3) );
1.78 +}
1.79 +
1.80 +// While loop
1.81 +template <class Arg1, class Arg2>
1.82 +inline const
1.83 +lambda_functor<
1.84 + lambda_functor_base<
1.85 + whileloop_action,
1.86 + tuple<lambda_functor<Arg1>, lambda_functor<Arg2> >
1.87 + >
1.88 +>
1.89 +while_loop(const lambda_functor<Arg1>& a1, const lambda_functor<Arg2>& a2) {
1.90 + return
1.91 + lambda_functor_base<
1.92 + whileloop_action,
1.93 + tuple<lambda_functor<Arg1>, lambda_functor<Arg2> >
1.94 + >
1.95 + ( tuple<lambda_functor<Arg1>, lambda_functor<Arg2> >(a1, a2));
1.96 +}
1.97 +
1.98 +// No body case.
1.99 +template <class Arg1>
1.100 +inline const
1.101 +lambda_functor<
1.102 + lambda_functor_base<
1.103 + whileloop_no_body_action,
1.104 + tuple<lambda_functor<Arg1> >
1.105 + >
1.106 +>
1.107 +while_loop(const lambda_functor<Arg1>& a1) {
1.108 + return
1.109 + lambda_functor_base<
1.110 + whileloop_no_body_action,
1.111 + tuple<lambda_functor<Arg1> >
1.112 + >
1.113 + ( tuple<lambda_functor<Arg1> >(a1) );
1.114 +}
1.115 +
1.116 +
1.117 +// Do While loop
1.118 +template <class Arg1, class Arg2>
1.119 +inline const
1.120 +lambda_functor<
1.121 + lambda_functor_base<
1.122 + dowhileloop_action,
1.123 + tuple<lambda_functor<Arg1>, lambda_functor<Arg2> >
1.124 + >
1.125 +>
1.126 +do_while_loop(const lambda_functor<Arg1>& a1, const lambda_functor<Arg2>& a2) {
1.127 + return
1.128 + lambda_functor_base<
1.129 + dowhileloop_action,
1.130 + tuple<lambda_functor<Arg1>, lambda_functor<Arg2> >
1.131 + >
1.132 + ( tuple<lambda_functor<Arg1>, lambda_functor<Arg2> >(a1, a2));
1.133 +}
1.134 +
1.135 +// No body case.
1.136 +template <class Arg1>
1.137 +inline const
1.138 +lambda_functor<
1.139 + lambda_functor_base<
1.140 + dowhileloop_no_body_action,
1.141 + tuple<lambda_functor<Arg1> >
1.142 + >
1.143 +>
1.144 +do_while_loop(const lambda_functor<Arg1>& a1) {
1.145 + return
1.146 + lambda_functor_base<
1.147 + dowhileloop_no_body_action,
1.148 + tuple<lambda_functor<Arg1> >
1.149 + >
1.150 + ( tuple<lambda_functor<Arg1> >(a1));
1.151 +}
1.152 +
1.153 +
1.154 +// Control loop lambda_functor_base specializations.
1.155 +
1.156 +// Specialization for for_loop.
1.157 +template<class Args>
1.158 +class
1.159 +lambda_functor_base<forloop_action, Args> {
1.160 +public:
1.161 + Args args;
1.162 + template <class T> struct sig { typedef void type; };
1.163 +public:
1.164 + explicit lambda_functor_base(const Args& a) : args(a) {}
1.165 +
1.166 + template<class RET, CALL_TEMPLATE_ARGS>
1.167 + RET call(CALL_FORMAL_ARGS) const {
1.168 + for(detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS);
1.169 + detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS);
1.170 + detail::select(boost::tuples::get<2>(args), CALL_ACTUAL_ARGS))
1.171 +
1.172 + detail::select(boost::tuples::get<3>(args), CALL_ACTUAL_ARGS);
1.173 + }
1.174 +};
1.175 +
1.176 +// No body case
1.177 +template<class Args>
1.178 +class
1.179 +lambda_functor_base<forloop_no_body_action, Args> {
1.180 +public:
1.181 + Args args;
1.182 + template <class T> struct sig { typedef void type; };
1.183 +public:
1.184 + explicit lambda_functor_base(const Args& a) : args(a) {}
1.185 +
1.186 + template<class RET, CALL_TEMPLATE_ARGS>
1.187 + RET call(CALL_FORMAL_ARGS) const {
1.188 + for(detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS);
1.189 + detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS);
1.190 + detail::select(boost::tuples::get<2>(args), CALL_ACTUAL_ARGS)) {}
1.191 + }
1.192 +};
1.193 +
1.194 +
1.195 +// Specialization for while_loop.
1.196 +template<class Args>
1.197 +class
1.198 +lambda_functor_base<whileloop_action, Args> {
1.199 +public:
1.200 + Args args;
1.201 + template <class T> struct sig { typedef void type; };
1.202 +public:
1.203 + explicit lambda_functor_base(const Args& a) : args(a) {}
1.204 +
1.205 + template<class RET, CALL_TEMPLATE_ARGS>
1.206 + RET call(CALL_FORMAL_ARGS) const {
1.207 + while(detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS))
1.208 +
1.209 + detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS);
1.210 + }
1.211 +};
1.212 +
1.213 +// No body case
1.214 +template<class Args>
1.215 +class
1.216 +lambda_functor_base<whileloop_no_body_action, Args> {
1.217 +public:
1.218 + Args args;
1.219 + template <class T> struct sig { typedef void type; };
1.220 +public:
1.221 + explicit lambda_functor_base(const Args& a) : args(a) {}
1.222 +
1.223 + template<class RET, CALL_TEMPLATE_ARGS>
1.224 + RET call(CALL_FORMAL_ARGS) const {
1.225 + while(detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS)) {}
1.226 + }
1.227 +};
1.228 +
1.229 +// Specialization for do_while_loop.
1.230 +// Note that the first argument is the condition.
1.231 +template<class Args>
1.232 +class
1.233 +lambda_functor_base<dowhileloop_action, Args> {
1.234 +public:
1.235 + Args args;
1.236 + template <class T> struct sig { typedef void type; };
1.237 +public:
1.238 + explicit lambda_functor_base(const Args& a) : args(a) {}
1.239 +
1.240 + template<class RET, CALL_TEMPLATE_ARGS>
1.241 + RET call(CALL_FORMAL_ARGS) const {
1.242 + do {
1.243 + detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS);
1.244 + } while (detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS) );
1.245 + }
1.246 +};
1.247 +
1.248 +// No body case
1.249 +template<class Args>
1.250 +class
1.251 +lambda_functor_base<dowhileloop_no_body_action, Args> {
1.252 +public:
1.253 + Args args;
1.254 + template <class T> struct sig { typedef void type; };
1.255 +public:
1.256 + explicit lambda_functor_base(const Args& a) : args(a) {}
1.257 +
1.258 + template<class RET, CALL_TEMPLATE_ARGS>
1.259 + RET call(CALL_FORMAL_ARGS) const {
1.260 + do {} while (detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS) );
1.261 + }
1.262 +};
1.263 +
1.264 + // The code below is from Joel de Guzman, some name changes etc.
1.265 + // has been made.
1.266 +
1.267 +///////////////////////////////////////////////////////////////////////////////
1.268 +//
1.269 +// while_composite
1.270 +//
1.271 +// This composite has the form:
1.272 +//
1.273 +// while_(condition)
1.274 +// [
1.275 +// statement
1.276 +// ]
1.277 +//
1.278 +// While the condition (an lambda_functor) evaluates to true, statement
1.279 +// (another lambda_functor) is executed. The result type of this is void.
1.280 +// Note the trailing underscore after while_.
1.281 +//
1.282 +///////////////////////////////////////////////////////////////////////////////
1.283 +template <typename CondT, typename DoT>
1.284 +struct while_composite {
1.285 +
1.286 + typedef while_composite<CondT, DoT> self_t;
1.287 +
1.288 + template <class SigArgs>
1.289 + struct sig { typedef void type; };
1.290 +
1.291 + while_composite(CondT const& cond_, DoT const& do__)
1.292 + : cond(cond_), do_(do__) {}
1.293 +
1.294 + template <class Ret, CALL_TEMPLATE_ARGS>
1.295 + Ret call(CALL_FORMAL_ARGS) const
1.296 + {
1.297 + while (cond.internal_call(CALL_ACTUAL_ARGS))
1.298 + do_.internal_call(CALL_ACTUAL_ARGS);
1.299 + }
1.300 +
1.301 + CondT cond;
1.302 + DoT do_;
1.303 +};
1.304 +
1.305 +//////////////////////////////////
1.306 +template <typename CondT>
1.307 +struct while_gen {
1.308 +
1.309 + while_gen(CondT const& cond_)
1.310 + : cond(cond_) {}
1.311 +
1.312 + template <typename DoT>
1.313 + lambda_functor<while_composite<
1.314 + typename as_lambda_functor<CondT>::type,
1.315 + typename as_lambda_functor<DoT>::type> >
1.316 + operator[](DoT const& do_) const
1.317 + {
1.318 + typedef while_composite<
1.319 + typename as_lambda_functor<CondT>::type,
1.320 + typename as_lambda_functor<DoT>::type>
1.321 + result;
1.322 +
1.323 + return result(
1.324 + to_lambda_functor(cond),
1.325 + to_lambda_functor(do_));
1.326 + }
1.327 +
1.328 + CondT cond;
1.329 +};
1.330 +
1.331 +//////////////////////////////////
1.332 +template <typename CondT>
1.333 +inline while_gen<CondT>
1.334 +while_(CondT const& cond)
1.335 +{
1.336 + return while_gen<CondT>(cond);
1.337 +}
1.338 +
1.339 +///////////////////////////////////////////////////////////////////////////////
1.340 +//
1.341 +// do_composite
1.342 +//
1.343 +// This composite has the form:
1.344 +//
1.345 +// do_
1.346 +// [
1.347 +// statement
1.348 +// ]
1.349 +// .while_(condition)
1.350 +//
1.351 +// While the condition (an lambda_functor) evaluates to true, statement
1.352 +// (another lambda_functor) is executed. The statement is executed at least
1.353 +// once. The result type of this is void. Note the trailing
1.354 +// underscore after do_ and the the leading dot and the trailing
1.355 +// underscore before and after .while_.
1.356 +//
1.357 +///////////////////////////////////////////////////////////////////////////////
1.358 +template <typename DoT, typename CondT>
1.359 +struct do_composite {
1.360 +
1.361 + typedef do_composite<DoT, CondT> self_t;
1.362 +
1.363 + template <class SigArgs>
1.364 + struct sig { typedef void type; };
1.365 +
1.366 + do_composite(DoT const& do__, CondT const& cond_)
1.367 + : do_(do__), cond(cond_) {}
1.368 +
1.369 + template <class Ret, CALL_TEMPLATE_ARGS>
1.370 + Ret call(CALL_FORMAL_ARGS) const
1.371 + {
1.372 + do
1.373 + do_.internal_call(CALL_ACTUAL_ARGS);
1.374 + while (cond.internal_call(CALL_ACTUAL_ARGS));
1.375 + }
1.376 +
1.377 + DoT do_;
1.378 + CondT cond;
1.379 +};
1.380 +
1.381 +////////////////////////////////////
1.382 +template <typename DoT>
1.383 +struct do_gen2 {
1.384 +
1.385 + do_gen2(DoT const& do__)
1.386 + : do_(do__) {}
1.387 +
1.388 + template <typename CondT>
1.389 + lambda_functor<do_composite<
1.390 + typename as_lambda_functor<DoT>::type,
1.391 + typename as_lambda_functor<CondT>::type> >
1.392 + while_(CondT const& cond) const
1.393 + {
1.394 + typedef do_composite<
1.395 + typename as_lambda_functor<DoT>::type,
1.396 + typename as_lambda_functor<CondT>::type>
1.397 + result;
1.398 +
1.399 + return result(
1.400 + to_lambda_functor(do_),
1.401 + to_lambda_functor(cond));
1.402 + }
1.403 +
1.404 + DoT do_;
1.405 +};
1.406 +
1.407 +////////////////////////////////////
1.408 +struct do_gen {
1.409 +
1.410 + template <typename DoT>
1.411 + do_gen2<DoT>
1.412 + operator[](DoT const& do_) const
1.413 + {
1.414 + return do_gen2<DoT>(do_);
1.415 + }
1.416 +};
1.417 +
1.418 +do_gen const do_ = do_gen();
1.419 +
1.420 +///////////////////////////////////////////////////////////////////////////////
1.421 +//
1.422 +// for_composite
1.423 +//
1.424 +// This statement has the form:
1.425 +//
1.426 +// for_(init, condition, step)
1.427 +// [
1.428 +// statement
1.429 +// ]
1.430 +//
1.431 +// Where init, condition, step and statement are all lambda_functors. init
1.432 +// is executed once before entering the for-loop. The for-loop
1.433 +// exits once condition evaluates to false. At each loop iteration,
1.434 +// step and statement is called. The result of this statement is
1.435 +// void. Note the trailing underscore after for_.
1.436 +//
1.437 +///////////////////////////////////////////////////////////////////////////////
1.438 +template <typename InitT, typename CondT, typename StepT, typename DoT>
1.439 +struct for_composite {
1.440 +
1.441 + template <class SigArgs>
1.442 + struct sig { typedef void type; };
1.443 +
1.444 + for_composite(
1.445 + InitT const& init_,
1.446 + CondT const& cond_,
1.447 + StepT const& step_,
1.448 + DoT const& do__)
1.449 + : init(init_), cond(cond_), step(step_), do_(do__) {}
1.450 +
1.451 + template <class Ret, CALL_TEMPLATE_ARGS>
1.452 + Ret
1.453 + call(CALL_FORMAL_ARGS) const
1.454 + {
1.455 + for (init.internal_call(CALL_ACTUAL_ARGS); cond.internal_call(CALL_ACTUAL_ARGS); step.internal_call(CALL_ACTUAL_ARGS))
1.456 + do_.internal_call(CALL_ACTUAL_ARGS);
1.457 + }
1.458 +
1.459 + InitT init; CondT cond; StepT step; DoT do_; // lambda_functors
1.460 +};
1.461 +
1.462 +//////////////////////////////////
1.463 +template <typename InitT, typename CondT, typename StepT>
1.464 +struct for_gen {
1.465 +
1.466 + for_gen(
1.467 + InitT const& init_,
1.468 + CondT const& cond_,
1.469 + StepT const& step_)
1.470 + : init(init_), cond(cond_), step(step_) {}
1.471 +
1.472 + template <typename DoT>
1.473 + lambda_functor<for_composite<
1.474 + typename as_lambda_functor<InitT>::type,
1.475 + typename as_lambda_functor<CondT>::type,
1.476 + typename as_lambda_functor<StepT>::type,
1.477 + typename as_lambda_functor<DoT>::type> >
1.478 + operator[](DoT const& do_) const
1.479 + {
1.480 + typedef for_composite<
1.481 + typename as_lambda_functor<InitT>::type,
1.482 + typename as_lambda_functor<CondT>::type,
1.483 + typename as_lambda_functor<StepT>::type,
1.484 + typename as_lambda_functor<DoT>::type>
1.485 + result;
1.486 +
1.487 + return result(
1.488 + to_lambda_functor(init),
1.489 + to_lambda_functor(cond),
1.490 + to_lambda_functor(step),
1.491 + to_lambda_functor(do_));
1.492 + }
1.493 +
1.494 + InitT init; CondT cond; StepT step;
1.495 +};
1.496 +
1.497 +//////////////////////////////////
1.498 +template <typename InitT, typename CondT, typename StepT>
1.499 +inline for_gen<InitT, CondT, StepT>
1.500 +for_(InitT const& init, CondT const& cond, StepT const& step)
1.501 +{
1.502 + return for_gen<InitT, CondT, StepT>(init, cond, step);
1.503 +}
1.504 +
1.505 +} // lambda
1.506 +} // boost
1.507 +
1.508 +#endif // BOOST_LAMBDA_LOOPS_HPP