matches.hpp

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

HPP
996
字号
            /// the expression.            ///            /// An expression type \c E matches <tt>or_\<B0,B1,...Bn\></tt> if \c E            /// matches any \c Bx for \c x in <tt>[0,n)</tt>.            ///            /// When applying <tt>or_\<B0,B1,...Bn\></tt> as a transform with an            /// expression \c e of type \c E, state \c s and visitor \c v, it is            /// equivalent to <tt>Bx()(e, s, v)</tt>, where \c x is the lowest            /// number such that <tt>matches\<E,Bx\>::::value</tt> is \c true.            template<BOOST_PP_ENUM_PARAMS(BOOST_PROTO_MAX_LOGICAL_ARITY, typename G)>            struct or_ : proto::callable            {                typedef or_ proto_base_expr;                template<typename Sig>                struct result;                template<typename This, typename Expr, typename State, typename Visitor>                struct result<This(Expr, State, Visitor)>                {                    typedef typename detail::matches_<Expr, or_>::which which;                    typedef typename which::template result<void(Expr, State, Visitor)>::type type;                };                /// \param expr An expression                /// \param state The current state                /// \param visitor A visitor of arbitrary type                /// \pre <tt>matches\<Expr,or_\>::::value</tt> is \c true.                /// \return <tt>result\<void(Expr, State, Visitor)\>::::which()(expr, state, visitor)</tt>                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 typename detail::matches_<Expr, or_>::which which;                    return which()(expr, state, visitor);                }            };            /// \brief For matching all of a set of grammars. When used as a            /// transform, \c and_\<\> applies the transform associated with            /// the last grammar in the set.            ///            /// An expression type \c E matches <tt>and_\<B0,B1,...Bn\></tt> if \c E            /// matches all \c Bx for \c x in <tt>[0,n)</tt>.            ///            /// When applying <tt>and_\<B0,B1,...Bn\></tt> as a transform with an            /// expression \c e, state \c s and visitor \c v, it is            /// equivalent to <tt>Bn()(e, s, v)</tt>.            template<BOOST_PP_ENUM_PARAMS(BOOST_PROTO_MAX_LOGICAL_ARITY, typename G)>            struct and_ : proto::callable            {                typedef and_ proto_base_expr;                template<typename Sig>                struct result;                template<typename This, typename Expr, typename State, typename Visitor>                struct result<This(Expr, State, Visitor)>                {                    typedef typename detail::last<and_>::type which;                    typedef typename which::template result<void(Expr, State, Visitor)>::type type;                };                /// \param expr An expression                /// \param state The current state                /// \param visitor A visitor of arbitrary type                /// \pre <tt>matches\<Expr,and_\>::::value</tt> is \c true.                /// \return <tt>result\<void(Expr, State, Visitor)\>::::which()(expr, state, visitor)</tt>                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 typename detail::last<and_>::type which;                    return which()(expr, state, visitor);                }            };            /// \brief For matching one of a set of alternate grammars, which            /// are looked up based on an expression's tag type. When used as a            /// transform, \c switch_\<\> applies the transform associated with            /// the grammar that matches the expression.            ///            /// \note \c switch_\<\> is functionally identical to \c or_\<\> but            /// is often more efficient. It does a fast, O(1) lookup based on an            /// expression's tag type to find a sub-grammar that may potentially            /// match the expression.            ///            /// An expression type \c E matches <tt>switch_\<C\></tt> if \c E            /// matches <tt>C::case_\<E::proto_tag\></tt>.            ///            /// When applying <tt>switch_\<C\></tt> as a transform with an            /// expression \c e of type \c E, state \c s and visitor \c v, it is            /// equivalent to <tt>C::case_\<E::proto_tag\>()(e, s, v)</tt>.            template<typename Cases>            struct switch_ : proto::callable            {                typedef switch_ proto_base_expr;                template<typename Sig>                struct result;                template<typename This, typename Expr, typename State, typename Visitor>                struct result<This(Expr, State, Visitor)>                {                    typedef typename Cases::template case_<typename Expr::proto_tag> which;                    typedef typename which::template result<void(Expr, State, Visitor)>::type type;                };                /// \param expr An expression                /// \param state The current state                /// \param visitor A visitor of arbitrary type                /// \pre <tt>matches\<Expr,switch_\>::::value</tt> is \c true.                /// \return <tt>result\<void(Expr, State, Visitor)\>::::which()(expr, state, visitor)</tt>                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 typename Cases::template case_<typename Expr::proto_tag> which;                    return which()(expr, state, visitor);                }            };            /// \brief For forcing exact matches of terminal types.            ///            /// By default, matching terminals ignores references and            /// cv-qualifiers. For instance, a terminal expression of            /// type <tt>terminal\<int const &\>::::type</tt> will match            /// the grammar <tt>terminal\<int\></tt>. If that is not            /// desired, you can force an exact match with            /// <tt>terminal\<exact\<int\> \></tt>. This will only            /// match integer terminals where the terminal is held by            /// value.            template<typename T>            struct exact            {};            /// \brief For matching terminals that are convertible to            /// a type.            ///            /// Use \c convertible_to\<\> to match a terminal that is            /// convertible to some type. For example, the grammar            /// <tt>terminal\<convertible_to\<int\> \></tt> will match            /// any terminal whose argument is convertible to an integer.            ///            /// \note The trait \c is_convertible\<\> from Boost.Type_traits            /// is used to determinal convertibility.            template<typename T>            struct convertible_to            {};            /// \brief For matching a Grammar to a variable number of            /// sub-expressions.            ///            /// An expression type <tt>expr\<AT, argsN\<A0,...An,U0,...Um\> \></tt>            /// matches a grammar <tt>expr\<BT, argsM\<B0,...Bn,vararg\<V\> \> \></tt>            /// if \c BT is \c _ or \c AT, and if \c Ax matches \c Bx            /// for each \c x in <tt>[0,n)</tt> and if \c Ux matches \c V            /// for each \c x in <tt>[0,m)</tt>.            ///            /// For example:            ///            /// \code            /// // Match any function call expression, irregardless            /// // of the number of function arguments:            /// struct Function            ///   : function< vararg<_> >            /// {};            /// \endcode            ///            /// When used as a transform, <tt>vararg\<G\></tt> applies            /// <tt>G</tt>'s transform.            template<typename Grammar>            struct vararg              : Grammar            {                typedef void proto_is_vararg_;            };        }        /// INTERNAL ONLY        ///        template<BOOST_PP_ENUM_PARAMS(BOOST_PROTO_MAX_LOGICAL_ARITY, typename G)>        struct is_callable<or_<BOOST_PP_ENUM_PARAMS(BOOST_PROTO_MAX_LOGICAL_ARITY, G)> >          : mpl::true_        {};        /// INTERNAL ONLY        ///        template<BOOST_PP_ENUM_PARAMS(BOOST_PROTO_MAX_LOGICAL_ARITY, typename G)>        struct is_callable<and_<BOOST_PP_ENUM_PARAMS(BOOST_PROTO_MAX_LOGICAL_ARITY, G)> >          : mpl::true_        {};        /// INTERNAL ONLY        ///        template<typename Grammar>        struct is_callable<not_<Grammar> >          : mpl::true_        {};        /// INTERNAL ONLY        ///        template<typename If, typename Then, typename Else>        struct is_callable<if_<If, Then, Else> >          : mpl::true_        {};        /// INTERNAL ONLY        ///        template<typename Grammar>        struct is_callable<vararg<Grammar> >          : mpl::true_        {};    }}    #if defined(_MSC_VER) && (_MSC_VER >= 1020)    # pragma warning(pop)    #endif    #endif#elif BOOST_PP_ITERATION_FLAGS() == 1    #define N BOOST_PP_ITERATION()            template<bool B, BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(N), typename P)>            struct BOOST_PP_CAT(and, N)              : BOOST_PP_CAT(and, BOOST_PP_DEC(N))<                    P0::value BOOST_PP_COMMA_IF(BOOST_PP_SUB(N,2))                    BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_DEC(N), P)                >            {};            template<BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(N), typename P)>            struct BOOST_PP_CAT(and, N)<false, BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(N), P)>              : mpl::false_            {};        #if N <= BOOST_PROTO_MAX_LOGICAL_ARITY            template<BOOST_PP_ENUM_PARAMS(N, typename G)>            struct last<proto::and_<BOOST_PP_ENUM_PARAMS(N, G)> >            {                typedef BOOST_PP_CAT(G, BOOST_PP_DEC(N)) type;            };            template<bool B, typename Expr, BOOST_PP_ENUM_PARAMS(N, typename G)>            struct BOOST_PP_CAT(or, N)              : BOOST_PP_CAT(or, BOOST_PP_DEC(N))<                    matches_<Expr, typename G1::proto_base_expr>::value                  , Expr, BOOST_PP_ENUM_SHIFTED_PARAMS(N, G)                >            {};            template<typename Expr BOOST_PP_ENUM_TRAILING_PARAMS(N, typename G)>            struct BOOST_PP_CAT(or, N)<true, Expr, BOOST_PP_ENUM_PARAMS(N, G)>              : mpl::true_            {                typedef G0 which;            };            // handle proto::or_            template<typename Expr, BOOST_PP_ENUM_PARAMS(N, typename G)>            struct matches_<Expr, proto::or_<BOOST_PP_ENUM_PARAMS(N, G)> >              : BOOST_PP_CAT(or, N)<                    matches_<typename Expr::proto_base_expr, typename G0::proto_base_expr>::value,                    typename Expr::proto_base_expr, BOOST_PP_ENUM_PARAMS(N, G)                >            {};            // handle proto::and_            template<typename Expr, BOOST_PP_ENUM_PARAMS(N, typename G)>            struct matches_<Expr, proto::and_<BOOST_PP_ENUM_PARAMS(N, G)> >              : detail::BOOST_PP_CAT(and, N)<                    BOOST_PROTO_DEFINE_MATCHES(~, 0, ~)::value,                    BOOST_PP_ENUM_SHIFTED(N, BOOST_PROTO_DEFINE_MATCHES, ~)                >            {};        #endif    #undef N#elif BOOST_PP_ITERATION_FLAGS() == 2    #define N BOOST_PP_ITERATION()            template<typename Args, typename Back, long To>            struct vararg_matches_impl<Args, Back, N, To>              : and2<                    matches_<typename Args::BOOST_PP_CAT(arg, BOOST_PP_DEC(N))::proto_base_expr, Back>::value                  , vararg_matches_impl<Args, Back, N + 1, To>                >            {};            template<typename Args, typename Back>            struct vararg_matches_impl<Args, Back, N, N>              : matches_<typename Args::BOOST_PP_CAT(arg, BOOST_PP_DEC(N))::proto_base_expr, Back>            {};            template<                template<BOOST_PP_ENUM_PARAMS(N, typename BOOST_PP_INTERCEPT)> class T                BOOST_PP_ENUM_TRAILING_PARAMS(N, typename Expr)                BOOST_PP_ENUM_TRAILING_PARAMS(N, typename Grammar)            >            struct lambda_matches<T<BOOST_PP_ENUM_PARAMS(N, Expr)>, T<BOOST_PP_ENUM_PARAMS(N, Grammar)> BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(N) >              : BOOST_PP_CAT(and, N)<                    BOOST_PROTO_DEFINE_LAMBDA_MATCHES(~, 0, ~)::value,                    BOOST_PP_ENUM_SHIFTED(N, BOOST_PROTO_DEFINE_LAMBDA_MATCHES, ~)                >            {};            template<typename Tag, typename Args1, typename Args2>            struct matches_< proto::expr<Tag, Args1, N>, proto::expr<Tag, Args2, N> >              : BOOST_PP_CAT(and, N)<                    BOOST_PROTO_MATCHES_N_FUN(~, 0, ~)::value,                    BOOST_PP_ENUM_SHIFTED(N, BOOST_PROTO_MATCHES_N_FUN, ~)                >            {};            template<typename Tag, typename Args1, typename Args2>            struct matches_< proto::expr<Tag, Args1, N>, proto::expr<proto::_, Args2, N> >              : BOOST_PP_CAT(and, N)<                    BOOST_PROTO_MATCHES_N_FUN(~, 0, ~)::value,                    BOOST_PP_ENUM_SHIFTED(N, BOOST_PROTO_MATCHES_N_FUN, ~)                >            {};    #undef N#endif

⌨️ 快捷键说明

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