do_while.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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_DO_WHILE_HPP
  8. #define BOOST_PHOENIX_STATEMENT_DO_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)(do_while)
  15. , (meta_grammar) // Cond
  16. (meta_grammar) // Do
  17. )
  18. namespace boost { namespace phoenix
  19. {
  20. struct do_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. do
  28. boost::phoenix::eval(do_it, ctx);
  29. while (boost::phoenix::eval(cond, ctx));
  30. }
  31. };
  32. template <typename Dummy>
  33. struct default_actions::when<rule::do_while, Dummy>
  34. : call<do_while_eval, Dummy>
  35. {};
  36. template <typename Do>
  37. struct do_while_gen
  38. {
  39. do_while_gen(Do const& do_it)
  40. : do_(do_it) {}
  41. template <typename Cond>
  42. typename expression::do_while<Cond, Do>::type const
  43. while_(Cond const& cond) const
  44. {
  45. return expression::do_while<Cond, Do>::make(cond, do_);
  46. }
  47. Do const& do_;
  48. };
  49. struct do_gen
  50. {
  51. template <typename Do>
  52. do_while_gen<Do> const
  53. operator[](Do const& do_) const
  54. {
  55. return do_while_gen<Do>(do_);
  56. }
  57. };
  58. #ifndef BOOST_PHOENIX_NO_PREDEFINED_TERMINALS
  59. do_gen const do_ = {};
  60. #endif
  61. }}
  62. #endif