Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:32

0001 ///////////////////////////////////////////////////////////////////////////////
0002 /// \file eval.hpp
0003 /// Contains the eval() expression evaluator.
0004 //
0005 //  Copyright 2008 Eric Niebler. Distributed under the Boost
0006 //  Software License, Version 1.0. (See accompanying file
0007 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 #ifndef BOOST_PROTO_EVAL_HPP_EAN_03_29_2007
0010 #define BOOST_PROTO_EVAL_HPP_EAN_03_29_2007
0011 
0012 #include <boost/proto/proto_fwd.hpp> // BOOST_PROTO_CALLABLE
0013 #include <boost/type_traits/remove_reference.hpp>
0014 
0015 namespace boost { namespace proto
0016 {
0017 
0018     namespace result_of
0019     {
0020         /// \brief A metafunction for calculating the return type
0021         /// of \c proto::eval() given a certain \c Expr and \c Context
0022         /// types.
0023         ///
0024         /// \note The types \c Expr and \c Context should not be
0025         /// reference types. They may be cv-qualified, but the
0026         /// cv-qualification on the \c Context parameter is ignored.
0027         template<typename Expr, typename Context>
0028         struct eval
0029         {
0030             typedef typename Context::template eval<Expr>::result_type type;
0031         };
0032     }
0033 
0034     namespace functional
0035     {
0036         /// \brief A PolymorphicFunctionObject type for
0037         /// evaluating a given Proto expression with a given
0038         /// context.
0039         struct eval
0040         {
0041             BOOST_PROTO_CALLABLE()
0042 
0043             template<typename Sig>
0044             struct result;
0045 
0046             template<typename This, typename Expr, typename Context>
0047             struct result<This(Expr, Context)>
0048             {
0049                 typedef
0050                     typename proto::result_of::eval<
0051                         typename remove_reference<Expr>::type
0052                       , typename remove_reference<Context>::type
0053                     >::type
0054                 type;
0055             };
0056 
0057             /// \brief Evaluate a given Proto expression with a given
0058             /// context.
0059             /// \param expr The Proto expression to evaluate
0060             /// \param context The context in which the expression should be
0061             ///     evaluated.
0062             /// \return <tt>typename Context::template eval<Expr>()(expr, context)</tt>
0063             template<typename Expr, typename Context>
0064             typename proto::result_of::eval<Expr, Context>::type
0065             operator ()(Expr &e, Context &ctx) const
0066             {
0067                 return typename Context::template eval<Expr>()(e, ctx);
0068             }
0069 
0070             /// \overload
0071             ///
0072             template<typename Expr, typename Context>
0073             typename proto::result_of::eval<Expr, Context>::type
0074             operator ()(Expr &e, Context const &ctx) const
0075             {
0076                 return typename Context::template eval<Expr>()(e, ctx);
0077             }
0078 
0079             /// \overload
0080             ///
0081             template<typename Expr, typename Context>
0082             typename proto::result_of::eval<Expr const, Context>::type
0083             operator ()(Expr const &e, Context &ctx) const
0084             {
0085                 return typename Context::template eval<Expr const>()(e, ctx);
0086             }
0087 
0088             /// \overload
0089             ///
0090             template<typename Expr, typename Context>
0091             typename proto::result_of::eval<Expr const, Context>::type
0092             operator ()(Expr const &e, Context const &ctx) const
0093             {
0094                 return typename Context::template eval<Expr const>()(e, ctx);
0095             }
0096         };
0097     }
0098 
0099     /// \brief Evaluate a given Proto expression with a given
0100     /// context.
0101     /// \param expr The Proto expression to evaluate
0102     /// \param context The context in which the expression should be
0103     ///     evaluated.
0104     /// \return <tt>typename Context::template eval<Expr>()(expr, context)</tt>
0105     template<typename Expr, typename Context>
0106     typename proto::result_of::eval<Expr, Context>::type
0107     eval(Expr &e, Context &ctx)
0108     {
0109         return typename Context::template eval<Expr>()(e, ctx);
0110     }
0111 
0112     /// \overload
0113     ///
0114     template<typename Expr, typename Context>
0115     typename proto::result_of::eval<Expr, Context>::type
0116     eval(Expr &e, Context const &ctx)
0117     {
0118         return typename Context::template eval<Expr>()(e, ctx);
0119     }
0120 
0121     /// \overload
0122     ///
0123     template<typename Expr, typename Context>
0124     typename proto::result_of::eval<Expr const, Context>::type
0125     eval(Expr const &e, Context &ctx)
0126     {
0127         return typename Context::template eval<Expr const>()(e, ctx);
0128     }
0129 
0130     /// \overload
0131     ///
0132     template<typename Expr, typename Context>
0133     typename proto::result_of::eval<Expr const, Context>::type
0134     eval(Expr const &e, Context const &ctx)
0135     {
0136         return typename Context::template eval<Expr const>()(e, ctx);
0137     }
0138 }}
0139 
0140 #endif