while.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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_WHILE_HPP
  7. #define PHOENIX_STATEMENT_WHILE_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 while_eval
  13. {
  14. template <typename Env, typename Cond, typename Do>
  15. struct result
  16. {
  17. typedef void type;
  18. };
  19. template <typename RT, typename Env, typename Cond, typename Do>
  20. static void
  21. eval(Env const& env, Cond& cond, Do& do_)
  22. {
  23. while (cond.eval(env))
  24. do_.eval(env);
  25. }
  26. };
  27. template <typename Cond>
  28. struct while_gen
  29. {
  30. while_gen(Cond const& cond)
  31. : cond(cond) {}
  32. template <typename Do>
  33. actor<typename as_composite<while_eval, Cond, Do>::type>
  34. operator[](Do const& do_) const
  35. {
  36. return compose<while_eval>(cond, do_);
  37. }
  38. Cond cond;
  39. };
  40. template <typename Cond>
  41. inline while_gen<Cond>
  42. while_(Cond const& cond)
  43. {
  44. return while_gen<Cond>(cond);
  45. }
  46. }}
  47. #endif