Ticket #5905: new_switch.patch
File new_switch.patch, 7.3 KB (added by , 11 years ago) |
---|
-
boost/proto/proto_fwd.hpp
269 269 270 270 using namespace tagns_; 271 271 272 template<typename Expr> 273 struct tag_of; 274 272 275 //////////////////////////////////////////////////////////////////////////////////////////////// 273 276 struct _; 274 277 … … 359 362 template<typename Condition, typename Then = _, typename Else = not_<_> > 360 363 struct if_; 361 364 362 template<typename Cases >365 template<typename Cases, typename Transform = tag_of<_>() > 363 366 struct switch_; 364 367 365 368 template<typename T> … … 462 465 struct is_sub_domain_of; 463 466 464 467 template<typename Expr> 465 struct tag_of;466 467 template<typename Expr>468 468 struct arity_of; 469 469 470 470 template<typename T, typename Void = void> … … 741 741 template<typename Grammar> 742 742 struct pass_through; 743 743 744 template<typename Grammar = detail::_default >744 template<typename Grammar = detail::_default > 745 745 struct _default; 746 746 747 747 struct _expr; -
boost/proto/matches.hpp
10 10 #ifndef BOOST_PROTO_MATCHES_HPP_EAN_11_03_2006 11 11 #define BOOST_PROTO_MATCHES_HPP_EAN_11_03_2006 12 12 13 13 14 #include <boost/config.hpp> 14 15 #include <boost/detail/workaround.hpp> 15 16 #include <boost/preprocessor/cat.hpp> … … 402 403 {}; 403 404 404 405 // handle proto::switch_ 405 template<typename Expr, typename Tag, typename Args, long Arity, typename Cases> 406 struct matches_<Expr, proto::basic_expr<Tag, Args, Arity>, switch_<Cases> > 407 : matches_< 408 Expr 409 , proto::basic_expr<Tag, Args, Arity> 410 , typename Cases::template case_<Tag>::proto_grammar 411 > 406 template< typename Expr, typename Tag, typename Args, long Arity 407 , typename Cases, typename Transform 408 > 409 struct matches_ < Expr, proto::basic_expr<Tag, Args, Arity> 410 , switch_<Cases,Transform> 411 > 412 : matches_< Expr 413 , proto::basic_expr<Tag, Args, Arity> 414 , typename 415 Cases::template case_<typename 416 when<_,Transform>::template 417 impl<Expr,int,int>::result_type 418 >::proto_grammar 419 > 412 420 { 413 typedef typename Cases::template case_<Tag> which; 421 typedef when<_,Transform> applicant; 422 typedef typename applicant::template impl<Expr,int,int>::result_type selected_type; 423 typedef typename Cases::template case_<selected_type> which; 414 424 }; 425 426 template< typename Expr, typename Tag, typename Args, long Arity 427 , typename Cases 428 > 429 struct matches_ < Expr, proto::basic_expr<Tag, Args, Arity> 430 , switch_<Cases> 431 > 432 : matches_< Expr 433 , proto::basic_expr<Tag, Args, Arity> 434 , typename Cases::template 435 case_<Tag>::proto_grammar 436 > 437 { 438 typedef typename Cases::template case_<Tag> which; 439 }; 415 440 } 416 441 417 442 /// \brief A Boolean metafunction that evaluates whether a given … … 449 474 /// not match \c T. 450 475 /// \li An expression \c E matches <tt>switch_\<C\></tt> if 451 476 /// \c E matches <tt>C::case_\<E::proto_tag\></tt>. 477 /// \li An expression \c E matches <tt>switch_\<C,T\></tt> if 478 /// the result type of the transform \c T on \c E matches 479 /// <tt>C::case_\<boost::result_of\<T(E)\>::type\></tt>. 452 480 /// 453 481 /// A terminal expression <tt>expr\<AT,term\<A\> \></tt> matches 454 482 /// a grammar <tt>expr\<BT,term\<B\> \></tt> if \c BT is \c AT or … … 784 812 /// When applying <tt>switch_\<C\></tt> as a transform with an 785 813 /// expression \c e of type \c E, state \c s and data \c d, it is 786 814 /// equivalent to <tt>C::case_\<E::proto_tag\>()(e, s, d)</tt>. 815 template<typename Cases, typename Transform> 816 struct switch_ : transform< switch_<Cases,Transform> > 817 { 818 typedef switch_ proto_grammar; 819 typedef when<_,Transform> applicant; 820 821 template<typename Expr, typename State, typename Data> 822 struct impl 823 : Cases::template 824 case_ < typename applicant::template impl<Expr,State,Data>::result_type 825 >::template impl<Expr, State, Data> 826 {}; 827 828 template<typename Expr, typename State, typename Data> 829 struct impl<Expr &, State, Data> 830 : Cases::template 831 case_ <typename applicant::template impl<Expr,State,Data>::result_type 832 >::template impl<Expr &, State, Data> 833 {}; 834 }; 835 787 836 template<typename Cases> 788 struct switch_ : transform<switch_<Cases> >837 struct switch_<Cases> : transform< switch_<Cases> > 789 838 { 790 typedef switch_ proto_grammar; 839 typedef switch_ proto_grammar; 840 /// \param e An expression 841 /// \param s The current state 842 /// \param d A data of arbitrary type 843 /// \pre <tt>matches\<Expr,switch_\>::value</tt> is \c true. 844 /// \return <tt>which()(e, s, d)</tt>, where <tt>which</tt> is 845 /// <tt>Cases::case_<typename Expr::proto_tag></tt> 791 846 792 /// \param e An expression 793 /// \param s The current state 794 /// \param d A data of arbitrary type 795 /// \pre <tt>matches\<Expr,switch_\>::value</tt> is \c true. 796 /// \return <tt>which()(e, s, d)</tt>, where <tt>which</tt> is 797 /// <tt>Cases::case_<typename Expr::proto_tag></tt> 847 template<typename Expr, typename State, typename Data> 848 struct impl 849 : Cases::template case_<typename Expr::proto_tag>::template impl<Expr, State, Data> 850 {}; 798 851 799 template<typename Expr, typename State, typename Data> 800 struct impl 801 : Cases::template case_<typename Expr::proto_tag>::template impl<Expr, State, Data> 802 {}; 803 804 template<typename Expr, typename State, typename Data> 805 struct impl<Expr &, State, Data> 806 : Cases::template case_<typename Expr::proto_tag>::template impl<Expr &, State, Data> 807 {}; 852 template<typename Expr, typename State, typename Data> 853 struct impl<Expr &, State, Data> 854 : Cases::template case_<typename Expr::proto_tag>::template impl<Expr &, State, Data> 855 {}; 808 856 }; 809 857 810 858 /// \brief For forcing exact matches of terminal types. … … 901 949 902 950 /// INTERNAL ONLY 903 951 /// 904 template<typename Cases >905 struct is_callable<switch_<Cases > >952 template<typename Cases, typename Transform> 953 struct is_callable<switch_<Cases,Transform> > 906 954 : mpl::true_ 907 955 {}; 908 956 -
libs/proto/test/Jamfile.v2
31 31 [ run make_expr.cpp ] 32 32 [ run matches.cpp ] 33 33 [ run flatten.cpp ] 34 [ run new_switch.cpp ] 34 35 [ run toy_spirit.cpp ] 35 36 [ run toy_spirit2.cpp ] 36 37 [ run make.cpp ]