/src/contrib/boost/spirit/home/phoenix/statement/for.hpp

http://pythonocc.googlecode.com/ · C++ Header · 64 lines · 50 code · 8 blank · 6 comment · 1 complexity · 3f8dcbaf31f917277ad963b7d01e75ed MD5 · raw file

  1. /*=============================================================================
  2. Copyright (c) 2001-2007 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #ifndef PHOENIX_STATEMENT_FOR_HPP
  7. #define PHOENIX_STATEMENT_FOR_HPP
  8. #include <boost/spirit/home/phoenix/core/composite.hpp>
  9. #include <boost/spirit/home/phoenix/core/compose.hpp>
  10. namespace boost { namespace phoenix
  11. {
  12. struct for_eval
  13. {
  14. template <
  15. typename Env
  16. , typename Init, typename Cond, typename Step, typename Do>
  17. struct result
  18. {
  19. typedef void type;
  20. };
  21. template <
  22. typename RT, typename Env
  23. , typename Init, typename Cond, typename Step, typename Do>
  24. static void
  25. eval(
  26. Env const& env
  27. , Init& init, Cond& cond, Step& step, Do& do_)
  28. {
  29. for (init.eval(env); cond.eval(env); step.eval(env))
  30. do_.eval(env);
  31. }
  32. };
  33. template <typename Init, typename Cond, typename Step>
  34. struct for_gen
  35. {
  36. for_gen(Init const& init, Cond const& cond, Step const& step)
  37. : init(init), cond(cond), step(step) {}
  38. template <typename Do>
  39. actor<typename as_composite<for_eval, Init, Cond, Step, Do>::type>
  40. operator[](Do const& do_) const
  41. {
  42. return compose<for_eval>(init, cond, step, do_);
  43. }
  44. Init init;
  45. Cond cond;
  46. Step step;
  47. };
  48. template <typename Init, typename Cond, typename Step>
  49. inline for_gen<Init, Cond, Step>
  50. for_(Init const& init, Cond const& cond, Step const& step)
  51. {
  52. return for_gen<Init, Cond, Step>(init, cond, step);
  53. }
  54. }}
  55. #endif