Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:45:07

0001 /*==============================================================================
0002     Copyright (c) 2001-2010 Joel de Guzman
0003     Copyright (c) 2010 Thomas Heller
0004 
0005     Distributed under the Boost Software License, Version 1.0. (See accompanying
0006     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 ==============================================================================*/
0008 #ifndef BOOST_PHOENIX_CORE_REFERENCE_HPP
0009 #define BOOST_PHOENIX_CORE_REFERENCE_HPP
0010 
0011 #include <boost/phoenix/core/limits.hpp>
0012 #include <boost/ref.hpp>
0013 #include <boost/phoenix/core/actor.hpp>
0014 #include <boost/phoenix/core/terminal.hpp>
0015 #include <boost/utility/result_of.hpp>
0016 
0017 namespace boost { namespace phoenix
0018 {
0019     /////////////////////////////////////////////////////////////////////////////
0020     //
0021     // reference
0022     //
0023     //      function for evaluating references, e.g. ref(123)
0024     //
0025     /////////////////////////////////////////////////////////////////////////////
0026     namespace expression
0027     {
0028         template <typename T>
0029         struct reference
0030             : expression::terminal<reference_wrapper<T> >
0031         {
0032             typedef
0033                 typename expression::terminal<reference_wrapper<T> >::type
0034                 type;
0035 
0036             static const type make(T & t)
0037             {
0038                 typename reference<T>::type const e = {{boost::ref(t)}};
0039                 return e;
0040             }
0041         };
0042         
0043         template <typename T>
0044         struct reference<T const>
0045             : expression::terminal<reference_wrapper<T const> >
0046         {
0047             typedef
0048                 typename expression::terminal<reference_wrapper<T const> >::type
0049                 type;
0050 
0051             static const type make(T const & t)
0052             {
0053                 typename reference<T const>::type const e = {{boost::cref(t)}};
0054                 return e;
0055             }
0056         };
0057     }
0058 
0059     namespace rule
0060     {
0061         struct reference
0062             : expression::reference<proto::_>
0063         {};
0064     }
0065 
0066     template <typename T>
0067     inline
0068     typename expression::reference<T>::type const
0069     ref(T & t)
0070     {
0071         return expression::reference<T>::make(t);
0072     }
0073 
0074     template <typename T>
0075     inline
0076     typename expression::reference<T const>::type const
0077     cref(T const & t)
0078     {
0079         return expression::reference<T const>::make(t);
0080     }
0081 
0082     // Call out boost::reference_wrapper for special handling
0083     template<typename T>
0084     struct is_custom_terminal<boost::reference_wrapper<T> >
0085       : mpl::true_
0086     {};
0087 
0088     // Special handling for boost::reference_wrapper
0089     template<typename T>
0090     struct custom_terminal<boost::reference_wrapper<T> >
0091     {
0092         typedef T &result_type;
0093 
0094         template <typename Context>
0095         T &operator()(boost::reference_wrapper<T> r, Context &) const
0096         {
0097             return r;
0098         }
0099     };
0100     
0101     template<typename Expr>
0102     struct custom_terminal<boost::reference_wrapper<actor<Expr> > >
0103     {
0104         template <typename Sig>
0105         struct result;
0106 
0107         template <typename This, typename Context>
0108         struct result<This(boost::reference_wrapper<actor<Expr> > const &, Context)>
0109             : boost::result_of<evaluator(actor<Expr> &, Context)>
0110         {};
0111 
0112         template <typename This, typename Context>
0113         struct result<This(boost::reference_wrapper<actor<Expr> > &, Context)>
0114             : boost::result_of<evaluator(actor<Expr> &, Context)>
0115         {};
0116 
0117         template <typename Context>
0118         typename boost::result_of<evaluator(actor<Expr> &, Context const &)>::type
0119         operator()(boost::reference_wrapper<actor<Expr> > & r, Context const & ctx) const
0120         {
0121             return boost::phoenix::eval(r, ctx);
0122         }
0123     };
0124     
0125     template<typename Expr>
0126     struct custom_terminal<boost::reference_wrapper<actor<Expr> const> >
0127     {
0128         template <typename Sig>
0129         struct result;
0130 
0131         template <typename This, typename Context>
0132         struct result<This(boost::reference_wrapper<actor<Expr> const> const &, Context)>
0133             : boost::result_of<evaluator(actor<Expr> const&, Context)>
0134         {};
0135 
0136         template <typename This, typename Context>
0137         struct result<This(boost::reference_wrapper<actor<Expr> const> &, Context)>
0138             : boost::result_of<evaluator(actor<Expr> const&, Context)>
0139         {};
0140 
0141         template <typename Context>
0142         typename boost::result_of<evaluator(actor<Expr> const&, Context const &)>::type
0143         operator()(boost::reference_wrapper<actor<Expr> const> const & r, Context & ctx) const
0144         {
0145             return boost::phoenix::eval(unwrap_ref(r), ctx);
0146         }
0147     };
0148 }}
0149 
0150 #endif