1 /*==============================================================================
2 Copyright (c) 2001-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_CORE_REFERENCE_HPP
9 #define BOOST_PHOENIX_CORE_REFERENCE_HPP
11 #include <boost/phoenix/core/limits.hpp>
12 #include <boost/ref.hpp>
13 #include <boost/phoenix/core/actor.hpp>
14 #include <boost/phoenix/core/terminal.hpp>
15 #include <boost/utility/result_of.hpp>
17 namespace boost { namespace phoenix
19 /////////////////////////////////////////////////////////////////////////////
23 // function for evaluating references, e.g. ref(123)
25 /////////////////////////////////////////////////////////////////////////////
30 : expression::terminal<reference_wrapper<T> >
33 typename expression::terminal<reference_wrapper<T> >::type
36 static const type make(T & t)
38 typename reference<T>::type const e = {{boost::ref(t)}};
44 struct reference<T const>
45 : expression::terminal<reference_wrapper<T const> >
48 typename expression::terminal<reference_wrapper<T const> >::type
51 static const type make(T const & t)
53 typename reference<T const>::type const e = {{boost::cref(t)}};
62 : expression::reference<proto::_>
68 typename expression::reference<T>::type const
71 return expression::reference<T>::make(t);
76 typename expression::reference<T const>::type const
79 return expression::reference<T const>::make(t);
82 // Call out boost::reference_wrapper for special handling
84 struct is_custom_terminal<boost::reference_wrapper<T> >
88 // Special handling for boost::reference_wrapper
90 struct custom_terminal<boost::reference_wrapper<T> >
92 typedef T &result_type;
94 template <typename Context>
95 T &operator()(boost::reference_wrapper<T> r, Context &) const
101 template<typename Expr>
102 struct custom_terminal<boost::reference_wrapper<actor<Expr> > >
104 template <typename Sig>
107 template <typename This, typename Context>
108 struct result<This(boost::reference_wrapper<actor<Expr> > const &, Context)>
109 : boost::result_of<evaluator(actor<Expr> &, Context)>
112 template <typename This, typename Context>
113 struct result<This(boost::reference_wrapper<actor<Expr> > &, Context)>
114 : boost::result_of<evaluator(actor<Expr> &, Context)>
117 template <typename Context>
118 typename boost::result_of<evaluator(actor<Expr> &, Context const &)>::type
119 operator()(boost::reference_wrapper<actor<Expr> > & r, Context const & ctx) const
121 return boost::phoenix::eval(r, ctx);
125 template<typename Expr>
126 struct custom_terminal<boost::reference_wrapper<actor<Expr> const> >
128 template <typename Sig>
131 template <typename This, typename Context>
132 struct result<This(boost::reference_wrapper<actor<Expr> const> const &, Context)>
133 : boost::result_of<evaluator(actor<Expr> const&, Context)>
136 template <typename This, typename Context>
137 struct result<This(boost::reference_wrapper<actor<Expr> const> &, Context)>
138 : boost::result_of<evaluator(actor<Expr> const&, Context)>
141 template <typename Context>
142 typename boost::result_of<evaluator(actor<Expr> const&, Context const &)>::type
143 operator()(boost::reference_wrapper<actor<Expr> const> const & r, Context & ctx) const
145 return boost::phoenix::eval(unwrap_ref(r), ctx);