Imported Upstream version 1.51.0
[platform/upstream/boost.git] / boost / spirit / home / phoenix / scope / local_variable.hpp
1 /*=============================================================================
2     Copyright (c) 2001-2007 Joel de Guzman
3     Copyright (c) 2004 Daniel Wallin
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 PHOENIX_SCOPE_LOCAL_VARIABLE_HPP
9 #define PHOENIX_SCOPE_LOCAL_VARIABLE_HPP
10
11 #include <boost/spirit/home/phoenix/core/limits.hpp>
12 #include <boost/spirit/home/phoenix/detail/local_reference.hpp>
13 #include <boost/spirit/home/phoenix/scope/detail/local_variable.hpp>
14 #include <boost/spirit/home/phoenix/core/actor.hpp>
15 #include <boost/mpl/bool.hpp>
16
17 namespace boost { namespace phoenix
18 {
19     template <typename Key>
20     struct local_variable
21     {
22         typedef Key key_type;
23
24         // This will prevent actor::operator()() from kicking in.
25         // Actually, we do not need all actor::operator()s for
26         // all arities, but this will suffice. The nullary 
27         // actor::operator() is particularly troublesome because 
28         // it is always eagerly evaluated by the compiler.
29         typedef mpl::true_ no_nullary; 
30
31         template <typename Env>
32         struct result : detail::apply_local<local_variable<Key>, Env> {};
33
34         template <typename Env>
35         typename result<Env>::type 
36         eval(Env const& env) const
37         {
38             typedef typename result<Env>::type return_type;
39             typedef typename 
40                 detail::get_index<typename Env::map_type, Key>::type 
41             index_type;
42             typedef detail::eval_local<Key> eval_local;
43
44             return eval_local::template get<return_type>(
45                 env
46               , index_type());
47         }
48
49     private:
50         // silence MSVC warning C4512: assignment operator could not be generated
51         local_variable& operator= (local_variable const&);
52     };
53
54     namespace local_names
55     {
56         actor<local_variable<struct _a_key> > const _a 
57             = local_variable<struct _a_key>();
58         actor<local_variable<struct _b_key> > const _b 
59             = local_variable<struct _b_key>();
60         actor<local_variable<struct _c_key> > const _c 
61             = local_variable<struct _c_key>();
62         actor<local_variable<struct _d_key> > const _d 
63             = local_variable<struct _d_key>();
64         actor<local_variable<struct _e_key> > const _e 
65             = local_variable<struct _e_key>();
66         actor<local_variable<struct _f_key> > const _f 
67             = local_variable<struct _f_key>();
68         actor<local_variable<struct _g_key> > const _g 
69             = local_variable<struct _g_key>();
70         actor<local_variable<struct _h_key> > const _h 
71             = local_variable<struct _h_key>();
72         actor<local_variable<struct _i_key> > const _i 
73             = local_variable<struct _i_key>();
74         actor<local_variable<struct _j_key> > const _j 
75             = local_variable<struct _j_key>();
76         actor<local_variable<struct _k_key> > const _k 
77             = local_variable<struct _k_key>();
78         actor<local_variable<struct _l_key> > const _l 
79             = local_variable<struct _l_key>();
80         actor<local_variable<struct _m_key> > const _m 
81             = local_variable<struct _m_key>();
82         actor<local_variable<struct _n_key> > const _n 
83             = local_variable<struct _n_key>();
84         actor<local_variable<struct _o_key> > const _o 
85             = local_variable<struct _o_key>();
86         actor<local_variable<struct _p_key> > const _p 
87             = local_variable<struct _p_key>();
88         actor<local_variable<struct _q_key> > const _q 
89             = local_variable<struct _q_key>();
90         actor<local_variable<struct _r_key> > const _r 
91             = local_variable<struct _r_key>();
92         actor<local_variable<struct _s_key> > const _s 
93             = local_variable<struct _s_key>();
94         actor<local_variable<struct _t_key> > const _t 
95             = local_variable<struct _t_key>();
96         actor<local_variable<struct _u_key> > const _u 
97             = local_variable<struct _u_key>();
98         actor<local_variable<struct _v_key> > const _v 
99             = local_variable<struct _v_key>();
100         actor<local_variable<struct _w_key> > const _w 
101             = local_variable<struct _w_key>();
102         actor<local_variable<struct _x_key> > const _x 
103             = local_variable<struct _x_key>();
104         actor<local_variable<struct _y_key> > const _y 
105             = local_variable<struct _y_key>();
106         actor<local_variable<struct _z_key> > const _z 
107             = local_variable<struct _z_key>();
108     }
109 }}
110
111 #endif