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