while.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*==============================================================================
  2. Copyright (c) 2001-2010 Joel de Guzman
  3. Copyright (c) 2010 Thomas Heller
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. #ifndef BOOST_PHOENIX_STATEMENT_WHILE_HPP
  8. #define BOOST_PHOENIX_STATEMENT_WHILE_HPP
  9. #include <boost/phoenix/core/limits.hpp>
  10. #include <boost/phoenix/core/call.hpp>
  11. #include <boost/phoenix/core/expression.hpp>
  12. #include <boost/phoenix/core/meta_grammar.hpp>
  13. BOOST_PHOENIX_DEFINE_EXPRESSION(
  14. (boost)(phoenix)(while_)
  15. , (meta_grammar) // Cond
  16. (meta_grammar) // Do
  17. )
  18. namespace boost { namespace phoenix
  19. {
  20. struct while_eval
  21. {
  22. typedef void result_type;
  23. template <typename Cond, typename Do, typename Context>
  24. result_type
  25. operator()(Cond const& cond, Do const& do_it, Context const & ctx) const
  26. {
  27. while(boost::phoenix::eval(cond, ctx))
  28. {
  29. boost::phoenix::eval(do_it, ctx);
  30. }
  31. }
  32. };
  33. template <typename Dummy>
  34. struct default_actions::when<rule::while_, Dummy>
  35. : call<while_eval, Dummy>
  36. {};
  37. template <typename Cond>
  38. struct while_gen
  39. {
  40. while_gen(Cond const& cond_) : cond(cond_) {}
  41. template <typename Do>
  42. typename expression::while_<Cond, Do>::type const
  43. operator[](Do const& do_it) const
  44. {
  45. return expression::while_<Cond, Do>::make(cond, do_it);
  46. }
  47. Cond const& cond;
  48. };
  49. template <typename Cond>
  50. inline
  51. while_gen<Cond> const
  52. while_(Cond const& cond)
  53. {
  54. return while_gen<Cond>(cond);
  55. }
  56. }}
  57. #endif