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