1 /*==============================================================================
2 Copyright (c) 2005-2010 Joel de Guzman
3 Copyright (c) 2010 Thomas Heller
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_SCOPE_SCOPED_ENVIRONMENT_HPP
9 #define BOOST_PHOENIX_SCOPE_SCOPED_ENVIRONMENT_HPP
11 #include <boost/phoenix/core/limits.hpp>
12 #include <boost/mpl/int.hpp>
13 #include <boost/fusion/sequence/sequence_facade.hpp>
14 #include <boost/fusion/sequence/intrinsic/begin.hpp>
15 #include <boost/fusion/sequence/intrinsic/end.hpp>
16 #include <boost/fusion/sequence/intrinsic/size.hpp>
17 #include <boost/fusion/sequence/intrinsic/value_at.hpp>
18 #include <boost/fusion/sequence/intrinsic/at.hpp>
19 #include <boost/fusion/support/category_of.hpp>
20 #include <boost/fusion/include/pop_front.hpp>
21 #include <boost/utility/result_of.hpp>
23 namespace boost { namespace phoenix
25 template<typename Env, typename OuterEnv, typename Locals, typename Map>
26 struct scoped_environment
27 : fusion::sequence_facade<
28 scoped_environment<Env, OuterEnv, Locals, Map>
29 , fusion::random_access_traversal_tag
33 typedef OuterEnv outer_env_type;
34 typedef Locals locals_type;
39 , OuterEnv const &outer_env_
40 , Locals const &locals_
43 , outer_env(outer_env_)
47 scoped_environment(scoped_environment const & o)
49 , outer_env(o.outer_env)
54 OuterEnv const & outer_env;
55 Locals const & locals;
58 fusion::result_of::pop_front<
60 typename proto::detail::uncvref<Env>::type
65 args_type args() const
67 return fusion::pop_front(env);
70 #define BOOST_PHOENIX_ADAPT_SCOPED_ENVIRONMENT(INTRINSIC) \
71 template <typename Seq> \
75 typename fusion::result_of::INTRINSIC< \
76 typename mpl::eval_if_c< \
78 typename remove_reference< \
79 typename Seq::env_type \
83 typename proto::detail::uncvref< \
84 typename Seq::env_type \
87 , proto::detail::uncvref< \
88 typename Seq::env_type \
94 static type call(Seq & seq) \
96 return fusion::INTRINSIC(seq.env); \
100 BOOST_PHOENIX_ADAPT_SCOPED_ENVIRONMENT(begin);
101 BOOST_PHOENIX_ADAPT_SCOPED_ENVIRONMENT(end);
102 BOOST_PHOENIX_ADAPT_SCOPED_ENVIRONMENT(size);
103 #undef BOOST_PHOENIX_ADAPT_SCOPED_ENVIRONMENT
105 template <typename Seq, typename N>
109 typename fusion::result_of::value_at<
110 typename mpl::eval_if_c<
112 typename remove_reference<
113 typename Seq::env_type
117 typename proto::detail::uncvref<
118 typename Seq::env_type
121 , proto::detail::uncvref<
122 typename Seq::env_type
130 template <typename Seq, typename N>
134 typename fusion::result_of::at<
135 typename mpl::eval_if_c<
137 typename remove_reference<
138 typename Seq::env_type
142 typename proto::detail::uncvref<
143 typename Seq::env_type
146 , proto::detail::uncvref<
147 typename Seq::env_type
154 static type call(Seq & seq)
156 return fusion::at<N>(seq.env);
161 template <typename Env, typename Dummy = void>
162 struct is_scoped_environment : mpl::false_ {};
164 template <typename Env>
165 struct is_scoped_environment<Env&> : is_scoped_environment<Env> {};
167 template <typename Env, typename OuterEnv, typename Locals, typename Map>
168 struct is_scoped_environment<scoped_environment<Env, OuterEnv, Locals, Map> >
172 template <typename Env, typename OuterEnv, typename Locals, typename Map>
173 struct is_scoped_environment<scoped_environment<Env, OuterEnv, Locals, Map> const>