Index: boost/proto/proto_fwd.hpp =================================================================== --- boost/proto/proto_fwd.hpp (revision 74374) +++ boost/proto/proto_fwd.hpp (working copy) @@ -269,6 +269,9 @@ using namespace tagns_; + template + struct tag_of; + //////////////////////////////////////////////////////////////////////////////////////////////// struct _; @@ -359,7 +362,7 @@ template > struct if_; - template + template() > struct switch_; template @@ -462,9 +465,6 @@ struct is_sub_domain_of; template - struct tag_of; - - template struct arity_of; template @@ -741,7 +741,7 @@ template struct pass_through; - template + template struct _default; struct _expr; Index: boost/proto/matches.hpp =================================================================== --- boost/proto/matches.hpp (revision 74374) +++ boost/proto/matches.hpp (working copy) @@ -10,6 +10,7 @@ #ifndef BOOST_PROTO_MATCHES_HPP_EAN_11_03_2006 #define BOOST_PROTO_MATCHES_HPP_EAN_11_03_2006 + #include #include #include @@ -402,16 +403,40 @@ {}; // handle proto::switch_ - template - struct matches_, switch_ > - : matches_< - Expr - , proto::basic_expr - , typename Cases::template case_::proto_grammar - > + template< typename Expr, typename Tag, typename Args, long Arity + , typename Cases, typename Transform + > + struct matches_ < Expr, proto::basic_expr + , switch_ + > + : matches_< Expr + , proto::basic_expr + , typename + Cases::template case_::template + impl::result_type + >::proto_grammar + > { - typedef typename Cases::template case_ which; + typedef when<_,Transform> applicant; + typedef typename applicant::template impl::result_type selected_type; + typedef typename Cases::template case_ which; }; + + template< typename Expr, typename Tag, typename Args, long Arity + , typename Cases + > + struct matches_ < Expr, proto::basic_expr + , switch_ + > + : matches_< Expr + , proto::basic_expr + , typename Cases::template + case_::proto_grammar + > + { + typedef typename Cases::template case_ which; + }; } /// \brief A Boolean metafunction that evaluates whether a given @@ -449,6 +474,9 @@ /// not match \c T. /// \li An expression \c E matches switch_\ if /// \c E matches C::case_\. + /// \li An expression \c E matches switch_\ if + /// the result type of the transform \c T on \c E matches + /// C::case_\::type\>. /// /// A terminal expression expr\ \> matches /// a grammar expr\ \> if \c BT is \c AT or @@ -784,27 +812,47 @@ /// When applying switch_\ as a transform with an /// expression \c e of type \c E, state \c s and data \c d, it is /// equivalent to C::case_\()(e, s, d). + template + struct switch_ : transform< switch_ > + { + typedef switch_ proto_grammar; + typedef when<_,Transform> applicant; + + template + struct impl + : Cases::template + case_ < typename applicant::template impl::result_type + >::template impl + {}; + + template + struct impl + : Cases::template + case_ ::result_type + >::template impl + {}; + }; + template - struct switch_ : transform > + struct switch_ : transform< switch_ > { - typedef switch_ proto_grammar; + typedef switch_ proto_grammar; + /// \param e An expression + /// \param s The current state + /// \param d A data of arbitrary type + /// \pre matches\::value is \c true. + /// \return which()(e, s, d), where which is + /// Cases::case_ - /// \param e An expression - /// \param s The current state - /// \param d A data of arbitrary type - /// \pre matches\::value is \c true. - /// \return which()(e, s, d), where which is - /// Cases::case_ + template + struct impl + : Cases::template case_::template impl + {}; - template - struct impl - : Cases::template case_::template impl - {}; - - template - struct impl - : Cases::template case_::template impl - {}; + template + struct impl + : Cases::template case_::template impl + {}; }; /// \brief For forcing exact matches of terminal types. @@ -901,8 +949,8 @@ /// INTERNAL ONLY /// - template - struct is_callable > + template + struct is_callable > : mpl::true_ {}; Index: libs/proto/test/Jamfile.v2 =================================================================== --- libs/proto/test/Jamfile.v2 (revision 74374) +++ libs/proto/test/Jamfile.v2 (working copy) @@ -31,6 +31,7 @@ [ run make_expr.cpp ] [ run matches.cpp ] [ run flatten.cpp ] + [ run new_switch.cpp ] [ run toy_spirit.cpp ] [ run toy_spirit2.cpp ] [ run make.cpp ]