call.hpp

来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 526 行 · 第 1/2 页

HPP
526
字号
                /// Otherwise, return <tt>Fun()(expr, state, visitor)</tt>.                ///                /// \param expr The current expression                /// \param state The current state                /// \param visitor An arbitrary visitor                template<typename Expr, typename State, typename Visitor>                typename result<void(Expr, State, Visitor)>::type                operator ()(Expr const &expr, State const &state, Visitor &visitor) const                {                    typedef                        detail::call0<                            Fun                          , Expr                          , State                          , Visitor                        >                    impl;                    return impl::call(expr, state, visitor);                }            };            /// \brief Either call the PolymorphicFunctionObject with 1            /// argument, or invoke the PrimitiveTransform with 3            /// arguments.            template<typename Fun, typename A0>            struct call<Fun(A0)> : proto::callable            {                template<typename Sig>                struct result;                template<typename This, typename Expr, typename State, typename Visitor>                struct result<This(Expr, State, Visitor)>                {                    /// Let \c x be <tt>when\<_, A0\>()(expr, state, visitor)</tt> and \c X                    /// be the type of \c x.                    /// If \c Fun is a unary PolymorphicFunctionObject that accepts \c x,                    /// then \c type is a typedef for <tt>boost::result_of\<Fun(X)\>::::type</tt>.                    /// Otherwise, it is a typedef for <tt>boost::result_of\<Fun(X, State, Visitor)\>::::type</tt>.                    typedef                        typename detail::call1<                            Fun                          , typename when<_, A0>::template result<void(Expr, State, Visitor)>::type                          , State                          , Visitor                        >::type                    type;                };                /// Either call the PolymorphicFunctionObject with 1 argument:                /// the result of applying the \c A0 transform; or                /// invoke the PrimitiveTransform with 3 arguments:                /// result of applying the \c A0 transform, the state, and the                /// visitor.                ///                /// Let \c x be <tt>when\<_, A0\>()(expr, state, visitor)</tt>.                /// If \c Fun is a unary PolymorphicFunctionObject that accepts \c x,                /// then return <tt>Fun()(x)</tt>. Otherwise, return                /// <tt>Fun()(x, state, visitor)</tt>.                ///                /// \param expr The current expression                /// \param state The current state                /// \param visitor An arbitrary visitor                template<typename Expr, typename State, typename Visitor>                typename result<void(Expr, State, Visitor)>::type                operator ()(Expr const &expr, State const &state, Visitor &visitor) const                {                    typedef                        detail::call1<                            Fun                          , typename when<_, A0>::template result<void(Expr, State, Visitor)>::type                          , State                          , Visitor                        >                    impl;                    return impl::call(                        detail::as_lvalue(when<_, A0>()(expr, state, visitor))                      , state                      , visitor                    );                }            };            /// \brief Either call the PolymorphicFunctionObject with 2            /// arguments, or invoke the PrimitiveTransform with 3            /// arguments.            template<typename Fun, typename A0, typename A1>            struct call<Fun(A0, A1)> : proto::callable            {                template<typename Sig>                struct result;                template<typename This, typename Expr, typename State, typename Visitor>                struct result<This(Expr, State, Visitor)>                {                    /// Let \c x be <tt>when\<_, A0\>()(expr, state, visitor)</tt> and \c X                    /// be the type of \c x.                    /// Let \c y be <tt>when\<_, A1\>()(expr, state, visitor)</tt> and \c Y                    /// be the type of \c y.                    /// If \c Fun is a binary PolymorphicFunction object that accepts \c x                    /// and \c y, then \c type is a typedef for                    /// <tt>boost::result_of\<Fun(X, Y)\>::::type</tt>. Otherwise, it is                    /// a typedef for <tt>boost::result_of\<Fun(X, Y, Visitor)\>::::type</tt>.                    typedef                        typename detail::call2<                            Fun                          , typename when<_, A0>::template result<void(Expr, State, Visitor)>::type                          , typename when<_, A1>::template result<void(Expr, State, Visitor)>::type                          , Visitor                        >::type                    type;                };                /// Either call the PolymorphicFunctionObject with 2 arguments:                /// the result of applying the \c A0 transform, and the                /// result of applying the \c A1 transform; or invoke the                /// PrimitiveTransform with 3 arguments: the result of applying                /// the \c A0 transform, the result of applying the \c A1                /// transform, and the visitor.                ///                /// Let \c x be <tt>when\<_, A0\>()(expr, state, visitor)</tt>.                /// Let \c y be <tt>when\<_, A1\>()(expr, state, visitor)</tt>.                /// If \c Fun is a binary PolymorphicFunction object that accepts \c x                /// and \c y, return <tt>Fun()(x, y)</tt>. Otherwise, return                /// <tt>Fun()(x, y, visitor)</tt>.                ///                /// \param expr The current expression                /// \param state The current state                /// \param visitor An arbitrary visitor                template<typename Expr, typename State, typename Visitor>                typename result<void(Expr, State, Visitor)>::type                operator ()(Expr const &expr, State const &state, Visitor &visitor) const                {                    typedef                        detail::call2<                            Fun                          , typename when<_, A0>::template result<void(Expr, State, Visitor)>::type                          , typename when<_, A1>::template result<void(Expr, State, Visitor)>::type                          , Visitor                        >                    impl;                    return impl::call(                        detail::as_lvalue(when<_, A0>()(expr, state, visitor))                      , detail::as_lvalue(when<_, A1>()(expr, state, visitor))                      , visitor                    );                }            };            /// \brief Call the PolymorphicFunctionObject or the            /// PrimitiveTransform with the current expression, state            /// and visitor, transformed according to \c A0, \c A1, and            /// \c A2, respectively.            template<typename Fun, typename A0, typename A1, typename A2>            struct call<Fun(A0, A1, A2)> : proto::callable            {                template<typename Sig>                struct result;                template<typename This, typename Expr, typename State, typename Visitor>                struct result<This(Expr, State, Visitor)>                {                    typedef typename when<_, A0>::template result<void(Expr, State, Visitor)>::type a0;                    typedef typename when<_, A1>::template result<void(Expr, State, Visitor)>::type a1;                    typedef typename when<_, A2>::template result<void(Expr, State, Visitor)>::type a2;                    typedef typename boost::result_of<Fun(a0, a1, a2)>::type type;                };                /// Let \c x be <tt>when\<_, A0\>()(expr, state, visitor)</tt>.                /// Let \c y be <tt>when\<_, A1\>()(expr, state, visitor)</tt>.                /// Let \c z be <tt>when\<_, A2\>()(expr, state, visitor)</tt>.                /// Return <tt>Fun()(x, y, z)</tt>.                ///                /// \param expr The current expression                /// \param state The current state                /// \param visitor An arbitrary visitor                template<typename Expr, typename State, typename Visitor>                typename result<void(Expr, State, Visitor)>::type                operator ()(Expr const &expr, State const &state, Visitor &visitor) const                {                    Fun f;                    return f(                        detail::as_lvalue(when<_, A0>()(expr, state, visitor))                      , detail::as_lvalue(when<_, A1>()(expr, state, visitor))                      , detail::uncv(when<_, A2>()(expr, state, visitor)) // HACK                    );                }            };            #if BOOST_PROTO_MAX_ARITY > 3            #define BOOST_PP_ITERATION_PARAMS_1 (3, (4, BOOST_PROTO_MAX_ARITY, <boost/xpressive/proto/transform/call.hpp>))            #include BOOST_PP_ITERATE()            #endif        }        /// INTERNAL ONLY        ///        template<typename Fun>        struct is_callable<transform::call<Fun> >          : mpl::true_        {};    }}    #endif#else    #define N BOOST_PP_ITERATION()        /// \brief Call the PolymorphicFunctionObject \c Fun with the        /// current expression, state and visitor, transformed according        /// to \c A0 through \c AN.        template<typename Fun BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)>        struct call<Fun(BOOST_PP_ENUM_PARAMS(N, A))> : proto::callable        {            template<typename Sig>            struct result;            template<typename This, typename Expr, typename State, typename Visitor>            struct result<This(Expr, State, Visitor)>            {                #define TMP(Z, M, DATA)                                                             \                    typedef                                                                         \                        typename when<_, BOOST_PP_CAT(A, M)>                                        \                            ::template result<void(Expr, State, Visitor)>                           \                        ::type                                                                      \                    BOOST_PP_CAT(a, M);                                                             \                    /**/                BOOST_PP_REPEAT(N, TMP, ~)                #undef TMP                typedef                    typename boost::result_of<                        Fun(BOOST_PP_ENUM_PARAMS(N, a))                    >::type                type;            };            /// Let \c ax be <tt>when\<_, Ax\>()(expr, state, visitor)</tt>            /// for each \c x in <tt>[0,N]</tt>.            /// Return <tt>Fun()(a0, a1,... aN)</tt>.            ///            /// \param expr The current expression            /// \param state The current state            /// \param visitor An arbitrary visitor            template<typename Expr, typename State, typename Visitor>            typename result<void(Expr, State, Visitor)>::type            operator ()(Expr const &expr, State const &state, Visitor &visitor) const            {                Fun f;                #define TMP(Z, M, DATA) when<_, BOOST_PP_CAT(A, M)>()(expr, state, visitor)                return f(BOOST_PP_ENUM(N, TMP, ~));                #undef TMP            }        };    #undef N#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?