Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63772 - in sandbox/SOC/2010/phoenix3: boost/phoenix boost/phoenix/core boost/phoenix/core/detail boost/phoenix/statement boost/phoenix/statement/detail libs/phoenix/test libs/phoenix/test/statement
From: thom.heller_at_[hidden]
Date: 2010-07-08 20:05:02


Author: theller
Date: 2010-07-08 20:05:00 EDT (Thu, 08 Jul 2010)
New Revision: 63772
URL: http://svn.boost.org/trac/boost/changeset/63772

Log:
 + implementation of switch/case statements finished
Added:
   sandbox/SOC/2010/phoenix3/boost/phoenix/statement/detail/
   sandbox/SOC/2010/phoenix3/boost/phoenix/statement/detail/switch.hpp (contents, props changed)
Text files modified:
   sandbox/SOC/2010/phoenix3/boost/phoenix/core/actor.hpp | 2
   sandbox/SOC/2010/phoenix3/boost/phoenix/core/detail/compose_result_of.hpp | 2
   sandbox/SOC/2010/phoenix3/boost/phoenix/statement.hpp | 1
   sandbox/SOC/2010/phoenix3/boost/phoenix/statement/switch.hpp | 250 ++++++++++++++++++++++++---------------
   sandbox/SOC/2010/phoenix3/libs/phoenix/test/Jamfile | 2
   sandbox/SOC/2010/phoenix3/libs/phoenix/test/statement/switch_tests.cpp | 49 +++++--
   6 files changed, 194 insertions(+), 112 deletions(-)

Modified: sandbox/SOC/2010/phoenix3/boost/phoenix/core/actor.hpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/boost/phoenix/core/actor.hpp (original)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/core/actor.hpp 2010-07-08 20:05:00 EDT (Thu, 08 Jul 2010)
@@ -130,7 +130,7 @@
         {
             BOOST_PROTO_ASSERT_MATCHES( *this, eval_grammar );
             typename make_basic_environment<A0&>::type args(a0);
-
+
             return eval(*this, args);
         }
 

Modified: sandbox/SOC/2010/phoenix3/boost/phoenix/core/detail/compose_result_of.hpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/boost/phoenix/core/detail/compose_result_of.hpp (original)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/core/detail/compose_result_of.hpp 2010-07-08 20:05:00 EDT (Thu, 08 Jul 2010)
@@ -14,7 +14,7 @@
 #include <boost/phoenix/support/iterate.hpp>
 
 #define PHOENIX_ITERATION_PARAMS \
- (3, (1, PHOENIX_COMPOSITE_LIMIT, \
+ (3, (3, PHOENIX_COMPOSITE_LIMIT, \
     <boost/phoenix/core/detail/compose_ex.hpp>))
 #include PHOENIX_ITERATE()
 

Modified: sandbox/SOC/2010/phoenix3/boost/phoenix/statement.hpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/boost/phoenix/statement.hpp (original)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/statement.hpp 2010-07-08 20:05:00 EDT (Thu, 08 Jul 2010)
@@ -11,6 +11,7 @@
 #include <boost/phoenix/statement/do_while.hpp>
 #include <boost/phoenix/statement/for.hpp>
 #include <boost/phoenix/statement/if.hpp>
+#include <boost/phoenix/statement/switch.hpp>
 #include <boost/phoenix/statement/throw.hpp>
 #include <boost/phoenix/statement/try_catch.hpp>
 #include <boost/phoenix/statement/while.hpp>

Added: sandbox/SOC/2010/phoenix3/boost/phoenix/statement/detail/switch.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/statement/detail/switch.hpp 2010-07-08 20:05:00 EDT (Thu, 08 Jul 2010)
@@ -0,0 +1,352 @@
+/*==============================================================================
+ Copyright (c) 2005-2010 Joel de Guzman
+ Copyright (c) 2010 Thomas Heller
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+==============================================================================*/
+
+#if !PHOENIX_IS_ITERATING
+
+#ifndef PHOENIX_STATEMENT_DETAIL_SWITCH_HPP
+#define PHOENIX_STATEMENT_DETAIL_SWITCH_HPP
+
+#include <boost/preprocessor/cat.hpp>
+
+ template <typename A0>
+ struct switch_eval<A0>
+ {
+ typedef void result_type;
+
+ template <typename Env, typename Cond, typename Case0>
+ result_type
+ operator()(Env& env, Cond const& cond, Case0 const& case0) const
+ {
+ switch(eval(cond, env))
+ {
+ case A0::value: eval(case0, env); break;
+ }
+ }
+ };
+
+ template <typename Cond, typename Cases>
+ struct make_switch<Cond, Cases, 1, true>
+ {
+ typedef typename fusion::result_of::value_at_c<Cases, 0>::type case0;
+
+ typedef compose<
+ switch_default_eval<>
+ , Cond
+ , typename case0::case_type
+ > composite_type;
+
+ typedef typename composite_type::type type;
+
+ type const
+ operator()( Cond const& cond, Cases const& cases) const
+ {
+ return composite_type()(cond, fusion::at_c<0>(cases).case_);
+ }
+ };
+
+ template <typename A0, typename A1>
+ struct switch_eval<A0, A1>
+ {
+ typedef void result_type;
+
+ template <typename Env, typename Cond, typename Case0, typename Case1>
+ result_type
+ operator()(Env& env, Cond const& cond, Case0 const& case0, Case1 const& case1) const
+ {
+ switch(eval(cond, env))
+ {
+ case A0::value: eval(case0, env); break;
+ case A1::value: eval(case1, env); break;
+ }
+ }
+ };
+
+ template <typename Cond, typename Cases>
+ struct make_switch<Cond, Cases, 2, false>
+ {
+ typedef typename fusion::result_of::value_at_c<Cases, 0>::type case0;
+ typedef typename fusion::result_of::value_at_c<Cases, 1>::type case1;
+
+ typedef compose<
+ switch_eval<typename case0::value_type, typename case1::value_type >
+ , Cond
+ , typename case0::case_type
+ , typename case1::case_type
+ > composite_type;
+
+ typedef typename composite_type::type type;
+
+ type const
+ operator()( Cond const& cond, Cases const& cases) const
+ {
+ return composite_type()(cond, fusion::at_c<0>(cases).case_, fusion::at_c<1>(cases).case_);
+ }
+ };
+
+ template <typename A0, typename A1, typename A2>
+ struct switch_eval<A0, A1, A2>
+ {
+ typedef void result_type;
+
+ template <typename Env, typename Cond, typename Case0, typename Case1, typename Case2>
+ result_type
+ operator()(Env& env, Cond const& cond, Case0 const& case0, Case1 const& case1, Case2 const& case2) const
+ {
+ switch(eval(cond, env))
+ {
+ case A0::value: eval(case0, env); break;
+ case A1::value: eval(case1, env); break;
+ case A2::value: eval(case2, env); break;
+ }
+ }
+ };
+
+ template <typename Cond, typename Cases>
+ struct make_switch<Cond, Cases, 3, false>
+ {
+ typedef typename fusion::result_of::value_at_c<Cases, 0>::type case0;
+ typedef typename fusion::result_of::value_at_c<Cases, 1>::type case1;
+ typedef typename fusion::result_of::value_at_c<Cases, 2>::type case2;
+
+ typedef compose<
+ switch_eval<typename case0::value_type, typename case1::value_type, typename case2::value_type >
+ , Cond
+ , typename case0::case_type
+ , typename case1::case_type
+ , typename case2::case_type
+ > composite_type;
+
+ typedef typename composite_type::type type;
+
+ type const
+ operator()( Cond const& cond, Cases const& cases) const
+ {
+ return composite_type()(cond, fusion::at_c<0>(cases).case_, fusion::at_c<1>(cases).case_, fusion::at_c<2>(cases).case_);
+ }
+ };
+
+ template<>
+ struct switch_default_eval<>
+ {
+ typedef void result_type;
+
+ template <typename Env, typename Cond, typename Default>
+ result_type
+ operator()(Env& env, Cond const& cond, Default const& default_) const
+ {
+ switch(eval(cond, env))
+ {
+ default: eval(default_, env); break;
+ }
+ }
+ };
+
+ template <typename Cond, typename Cases>
+ struct make_switch<Cond, Cases, 1, false>
+ {
+ typedef typename fusion::result_of::value_at_c<Cases, 0>::type case0;
+
+ typedef compose<
+ switch_eval<typename case0::value_type >
+ , Cond
+ , typename case0::case_type
+ > composite_type;
+
+ typedef typename composite_type::type type;
+
+ type const
+ operator()( Cond const& cond, Cases const& cases) const
+ {
+ return composite_type()(cond, fusion::at_c<0>(cases).case_);
+ }
+ };
+
+ template<typename A0>
+ struct switch_default_eval<A0>
+ {
+ typedef void result_type;
+
+ template <typename Env, typename Cond, typename Case0, typename Default>
+ result_type
+ operator()(Env& env, Cond const& cond, Case0 const& case0, Default const& default_) const
+ {
+ switch(eval(cond, env))
+ {
+ case A0::value: eval(case0, env); break;
+ default: eval(default_, env); break;
+ }
+ }
+ };
+
+ template <typename Cond, typename Cases>
+ struct make_switch<Cond, Cases, 2, true>
+ {
+ typedef typename fusion::result_of::value_at_c<Cases, 0>::type case0;
+ typedef typename fusion::result_of::value_at_c<Cases, 1>::type case1;
+
+ typedef compose<
+ switch_default_eval<typename case0::value_type>
+ , Cond
+ , typename case0::case_type
+ , case1
+ > composite_type;
+
+ typedef typename composite_type::type type;
+
+ type const
+ operator()( Cond const& cond, Cases const& cases) const
+ {
+ return composite_type()(cond, fusion::at_c<0>(cases).case_, fusion::at_c<1>(cases).case_);
+ }
+ };
+
+ template<typename A0, typename A1>
+ struct switch_default_eval<A0, A1>
+ {
+ typedef void result_type;
+
+ template <typename Env, typename Cond, typename Case0, typename Case1, typename Default>
+ result_type
+ operator()(Env& env, Cond const& cond, Case0 const& case0, Case1 const& case1, Default const& default_) const
+ {
+ switch(eval(cond, env))
+ {
+ case A0::value: eval(case0, env); break;
+ case A1::value: eval(case1, env); break;
+ default: eval(default_, env); break;
+ }
+ }
+ };
+
+ template <typename Cond, typename Cases>
+ struct make_switch<Cond, Cases, 3, true>
+ {
+ typedef typename fusion::result_of::value_at_c<Cases, 0>::type case0;
+ typedef typename fusion::result_of::value_at_c<Cases, 1>::type case1;
+ typedef typename fusion::result_of::value_at_c<Cases, 2>::type case2;
+
+ typedef compose<
+ switch_default_eval<typename case0::value_type, typename case1::value_type>
+ , Cond
+ , typename case0::case_type
+ , typename case1::case_type
+ , typename case2::case_type
+ > composite_type;
+
+ typedef typename composite_type::type type;
+
+ type const
+ operator()( Cond const& cond, Cases const& cases) const
+ {
+ return composite_type()(cond, fusion::at_c<0>(cases).case_, fusion::at_c<1>(cases).case_, fusion::at_c<2>(cases).case_);
+ }
+ };
+
+#define PHOENIX_ITERATION_PARAMS \
+ (3, (4, PHOENIX_COMPOSITE_LIMIT, \
+ <boost/phoenix/statement/detail/switch.hpp>))
+#include PHOENIX_ITERATE()
+
+#endif
+
+#else
+
+#define PHOENIX_typename_CaseCond BOOST_PP_ENUM_PARAMS(PHOENIX_ITERATION, typename CaseCond)
+#define PHOENIX_CaseCond BOOST_PP_ENUM_PARAMS(PHOENIX_ITERATION, CaseCond)
+#define PHOENIX_typename_CaseCond_default BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(PHOENIX_ITERATION), typename CaseCond)
+#define PHOENIX_CaseCond_default BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(PHOENIX_ITERATION), CaseCond)
+
+ template <PHOENIX_typename_CaseCond>
+ struct switch_eval<PHOENIX_CaseCond>
+ {
+ typedef void result_type;
+
+ template <typename Env, typename Cond, PHOENIX_typename_A>
+ result_type
+ operator()(Env& env, Cond const& cond, PHOENIX_A_const_ref_a) const
+ {
+#define CASES(_,n,__) case CaseCond ## n ::value : eval( a ##n, env ); break;
+
+ switch(eval(cond, env))
+ {
+ BOOST_PP_REPEAT(PHOENIX_ITERATION, CASES, _)
+ }
+ }
+ };
+
+ template <typename Cond, typename Cases>
+ struct make_switch<Cond, Cases, PHOENIX_ITERATION, false>
+ {
+#define CASE_TYPEDEF(_,n,__) typedef typename fusion::result_of::value_at_c<Cases, n>::type case ## n;
+ BOOST_PP_REPEAT(PHOENIX_ITERATION, CASE_TYPEDEF, _)
+
+ typedef compose<
+ switch_eval<BOOST_PP_ENUM_BINARY_PARAMS(PHOENIX_ITERATION, typename case, ::value_type BOOST_PP_INTERCEPT)>
+ , Cond
+ , BOOST_PP_ENUM_BINARY_PARAMS(PHOENIX_ITERATION, typename case, ::case_type BOOST_PP_INTERCEPT)
+ > composite_type;
+
+ typedef typename composite_type::type type;
+
+ type const
+ operator()( Cond const& cond, Cases const& cases) const
+ {
+#define FUSION_AT_C(_, n, __) BOOST_PP_COMMA_IF(n) fusion::at_c< n >(cases).case_
+ return composite_type()(cond,
+ BOOST_PP_REPEAT(PHOENIX_ITERATION, FUSION_AT_C, _));
+ }
+ };
+
+ template <PHOENIX_typename_CaseCond_default>
+ struct switch_default_eval<PHOENIX_CaseCond_default>
+ {
+ typedef void result_type;
+
+ template <typename Env, typename Cond, PHOENIX_typename_A>
+ result_type
+ operator()(Env& env, Cond const& cond, PHOENIX_A_const_ref_a) const
+ {
+ switch(eval(cond, env))
+ {
+ BOOST_PP_REPEAT(BOOST_PP_DEC(PHOENIX_ITERATION), CASES, _)
+ default: eval(BOOST_PP_CAT(a, BOOST_PP_DEC(PHOENIX_ITERATION)), env);
+ }
+ }
+ };
+
+ template <typename Cond, typename Cases>
+ struct make_switch<Cond, Cases, PHOENIX_ITERATION, true>
+ {
+ BOOST_PP_REPEAT(PHOENIX_ITERATION, CASE_TYPEDEF, _)
+
+ typedef compose<
+ switch_default_eval<BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_DEC(PHOENIX_ITERATION), typename case, ::value_type BOOST_PP_INTERCEPT)>
+ , Cond
+ , BOOST_PP_ENUM_BINARY_PARAMS(PHOENIX_ITERATION, typename case, ::case_type BOOST_PP_INTERCEPT)
+ > composite_type;
+
+ typedef typename composite_type::type type;
+
+ type const
+ operator()( Cond const& cond, Cases const& cases) const
+ {
+ return composite_type()(cond,
+ BOOST_PP_REPEAT(PHOENIX_ITERATION, FUSION_AT_C, _));
+ }
+ };
+
+#undef FUSION_AT_C
+#undef CASE_TYPEDEF
+#undef CASES
+#undef PHOENIX_typename_CaseCond
+#undef PHOENIX_CaseCond
+#undef PHOENIX_typename_CaseCond_default
+#undef PHOENIX_CaseCond_default
+
+#endif
+

Modified: sandbox/SOC/2010/phoenix3/boost/phoenix/statement/switch.hpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/boost/phoenix/statement/switch.hpp (original)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/statement/switch.hpp 2010-07-08 20:05:00 EDT (Thu, 08 Jul 2010)
@@ -8,148 +8,210 @@
 #ifndef PHOENIX_STATEMENT_SWITCH_HPP
 #define PHOENIX_STATEMENT_SWITCH_HPP
 
+#include <boost/fusion/algorithm/transformation/push_front.hpp>
 #include <boost/fusion/sequence/intrinsic/at.hpp>
+#include <boost/fusion/sequence/intrinsic/value_at.hpp>
 #include <boost/phoenix/core/meta_grammar.hpp>
-#include <boost/phoenix/core/domain.hpp>
+#include <boost/phoenix/support/element_at.hpp>
+#include <boost/phoenix/support/iterate.hpp>
 
+#include <boost/proto/proto_fwd.hpp>
+#include <boost/proto/context/callable.hpp>
 #include <boost/proto/extends.hpp>
 #include <boost/proto/make_expr.hpp>
 
 namespace boost { namespace phoenix
 {
     struct switch_case_tag {};
+ struct switch_default_tag {};
 
- template <typename Expr>
- struct switch_actor;
+ template <typename Value, typename Case>
+ struct switch_case
+ {
+ typedef Value value_type;
+ typedef Case case_type;
+
+ switch_case(Case const& case_) : case_(case_) {};
 
- struct switch_domain
- : proto::domain<
- proto::pod_generator<switch_actor>,
- proto::_, proto::default_domain>
+ Case const& case_;
+ };
+
+ template <typename Case>
+ struct switch_default
     {
- template <typename T>
- struct as_child : as_expr<T>
- {};
+ typedef mpl::false_ value_type;
+ typedef Case case_type;
+
+ switch_default(Case const& case_) : case_(case_) {};
+
+ Case const& case_;
     };
 
- struct test
+ namespace detail
     {
- typedef void result_type;
+ struct push_front
+ : proto::callable
+ {
+ template <typename Sig>
+ struct result;
 
- test() { std::cout << "hmmmm\n";}
+ template <typename This, typename Expr, typename State>
+ struct result<This(Expr, State)>
+ : fusion::result_of::push_front<typename remove_reference<State>::type const, Expr>
+ {};
+
+ template <typename Expr, typename State>
+ typename fusion::result_of::push_front<State const, Expr>::type
+ operator()(Expr const& expr, State const& state)
+ {
+ return fusion::push_front(state, expr);
+ }
+
+ };
+
+ template <typename Case>
+ struct is_default
+ : mpl::false_
+ {};
 
- template <typename A0, typename A1>
- result_type
- operator()( A0 const& a0, A1 const& a1) const
- {
- std::cout << "ok ..\n";
- }
- };
+ template <typename Case>
+ struct is_default<switch_default<Case> >
+ : mpl::true_
+ {};
+ }
 
     struct switch_grammar
- : proto::or_<
- proto::when<
- proto::comma<switch_grammar, switch_grammar>
- , proto::_default<switch_grammar>
- >
- /* proto::when<
- proto::binary_expr<
- switch_case_tag
- , proto::_
- , proto::_
+ : /// FIXME
+ /*proto::and_<
+ // switch_(...)[default_(...), default_(...)] not allowed
+ proto::not_<
+ proto::comma<
+ proto::unary_expr<switch_default_tag, eval_grammar>
+ , proto::unary_expr<switch_default_tag, eval_grammar>
>
- //, proto::_child1(proto::_child0)
- //, proto::_default<switch_grammar>
- , proto::_child1()
>
- ,*/
- , proto::when<
- proto::binary_expr<switch_case_tag, proto::_, eval_grammar>
- , proto::_default<eval_grammar>
+ // switch_(...)[case_<...>(...), default_(...), case<...>(...)] not allowed
+ , proto::not_<
+ proto::comma<proto::comma<switch_grammar, proto::unary_expr<switch_default_tag, eval_grammar> >, switch_grammar >
>
- >
+ // switch_(...)[case_<...>(...), default_(...), default_(...)] not allowed
+ , proto::not_<
+ proto::comma<proto::comma<switch_grammar, proto::unary_expr<switch_default_tag, eval_grammar> >, proto::unary_expr<switch_default_tag, eval_grammar> >
+ >
+ // and finally the transforms to create the fusion vector of the actors
+ ,*/ proto::or_<
+ proto::when<
+ proto::comma<switch_grammar, switch_grammar>
+ , switch_grammar(proto::_left, switch_grammar(proto::_right))
+ >
+ , proto::when<
+ proto::binary_expr<switch_case_tag, proto::_, eval_grammar>
+ , detail::push_front(switch_case<proto::_value(proto::_left), proto::_right>(proto::_right), proto::_state)
+ >
+ , proto::when<
+ proto::unary_expr<switch_default_tag, eval_grammar>
+ , detail::push_front(switch_default<proto::_child>(proto::_child), proto::_state)
+ >
+ >
+ //>
     {};
 
- switch_grammar const switch_eval = switch_grammar();
+ template <PHOENIX_typename_A_void(PHOENIX_COMPOSITE_LIMIT), typename Dummy = void>
+ struct switch_eval;
 
- template <typename Expr>
- struct switch_actor
- {
- BOOST_PROTO_BASIC_EXTENDS(Expr, switch_actor<Expr>, switch_domain)
- BOOST_PROTO_EXTENDS_ASSIGN()
- BOOST_PROTO_EXTENDS_SUBSCRIPT()
+ template <PHOENIX_typename_A_void(BOOST_PP_DEC(PHOENIX_COMPOSITE_LIMIT)), typename Dummy = void>
+ struct switch_default_eval;
 
- typedef void result_type;
+ template <
+ typename Cond,
+ typename Cases, int N = fusion::result_of::size<Cases>::type::value,
+ bool with_default = detail::is_default<typename fusion::result_of::value_at_c<Cases, N-1>::type >::value>
+ struct make_switch;
 
- result_type
- operator()() const
- {
- switch_eval(*this);
- std::cout << "blubb0\n";
- std::cout << typeid(Expr).name() << "\n";
- }
+ // Bring in the rest ....
+ #include <boost/phoenix/statement/detail/switch.hpp>
 
- template <typename A0>
- result_type
- operator()(A0 const& a0) const
- {
- std::cout << "blubb1\n";
- switch_eval(*this);
- }
-
- template <typename A0, typename A1>
- result_type
- operator()(A0 const& a0, A1 const& a1) const
- {
- std::cout << "blubb2\n";
- switch_eval(*this);
- }
-
- template <typename A0, typename A1, typename A2>
- result_type
- operator()(A0 const& a0, A1 const& a1, A1 const& a2) const
- {
- std::cout << "blubb3\n";
- switch_eval(*this);
- }
- };
-
     template <int N, typename A0>
- switch_actor<
- typename proto::result_of::make_expr<
- switch_case_tag
- , default_domain_with_basic_expr
- , int
- , A0
- >::type
- >const
+ typename proto::result_of::make_expr<
+ switch_case_tag
+ , default_domain_with_basic_expr
+ , mpl::int_<N>
+ , A0
+ >::type const
     case_(A0 const& a0)
     {
         typedef typename
             proto::result_of::make_expr<
                 switch_case_tag
               , default_domain_with_basic_expr
- , int
+ , mpl::int_<N>
+ , A0
+ >::type
+ expr_type;
+
+ expr_type const e = {mpl::int_<N>(), a0};
+ return e;
+ }
+
+ template <typename A0>
+ typename proto::result_of::make_expr<
+ switch_default_tag
+ , default_domain_with_basic_expr
+ , A0
+ >::type const
+ default_(A0 const& a0)
+ {
+ typedef typename
+ proto::result_of::make_expr<
+ switch_default_tag
+ , default_domain_with_basic_expr
               , A0
>::type
             expr_type;
 
- switch_actor<expr_type> const e = {{N, a0}};
+ expr_type const e = {a0};
         return e;
     }
 
-/*
     template <typename Cond>
- switch_gen<Cond>
+ struct switch_gen
+ {
+ switch_gen(Cond const& cond) : cond(cond) {}
+
+ template <typename Cases>
+ typename make_switch<
+ Cond
+ , typename fusion::result_of::as_vector<
+ typename boost::result_of<
+ switch_grammar(Cases const&, fusion::vector0<> const&)
+ >::type
+ >::type
+ >::type
+ operator[](Cases const& cases) const
+ {
+ BOOST_PROTO_ASSERT_MATCHES( cases, switch_grammar );
+ typedef
+ typename fusion::result_of::as_vector<
+ typename boost::result_of<
+ switch_grammar(Cases const&, fusion::vector0<> const&)
+ >::type
+ >::type
+ cases_type;
+
+ return make_switch<Cond, cases_type>()(cond, fusion::as_vector(switch_grammar()(cases, fusion::vector0<>())));
+ }
+
+ Cond const& cond;
+ };
+
+ template <typename Cond>
+ switch_gen<Cond> const
     switch_(Cond const& cond)
     {
         return switch_gen<Cond>(cond);
     };
 
- template <int N, typename A0>
- switch_case<A0, int
- */
-
 }}
 
 #endif
+

Modified: sandbox/SOC/2010/phoenix3/libs/phoenix/test/Jamfile
==============================================================================
--- sandbox/SOC/2010/phoenix3/libs/phoenix/test/Jamfile (original)
+++ sandbox/SOC/2010/phoenix3/libs/phoenix/test/Jamfile 2010-07-08 20:05:00 EDT (Thu, 08 Jul 2010)
@@ -53,7 +53,7 @@
 test-suite phoenix_statement :
     [ run statement/if_tests.cpp ]
     [ run statement/loops_tests.cpp ]
-# [ run statement/switch_tests.cpp ]
+ [ run statement/switch_tests.cpp ]
     [ run statement/exceptions.cpp ]
     ;
         

Modified: sandbox/SOC/2010/phoenix3/libs/phoenix/test/statement/switch_tests.cpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/libs/phoenix/test/statement/switch_tests.cpp (original)
+++ sandbox/SOC/2010/phoenix3/libs/phoenix/test/statement/switch_tests.cpp 2010-07-08 20:05:00 EDT (Thu, 08 Jul 2010)
@@ -12,13 +12,21 @@
 #include <boost/phoenix/operator.hpp>
 #include <boost/phoenix/core.hpp>
 
-using namespace boost::phoenix;
-using namespace boost::phoenix::arg_names;
-using namespace std;
-
 int
 main()
 {
+ using boost::phoenix::arg_names::_1;
+ using boost::phoenix::case_;
+ using boost::phoenix::default_;
+ using boost::phoenix::switch_;
+ using boost::phoenix::ref;
+ using boost::phoenix::val;
+
+ using std::cout;
+ using std::endl;
+ using std::vector;
+ using std::for_each;
+
     int init[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
     vector<int> v(init, init+10);
 
@@ -26,7 +34,8 @@
         switch_(_1)
         [
             // wierd case, why not just use if(...), but valid, nonetheless
- case_<4>(cout << val("<4>") << endl)
+ //case_<4>(cout << val("<4>") << endl)
+ case_<4>(cout << ref("<4>") << endl)
         ]
     );
 
@@ -36,7 +45,8 @@
         switch_(_1)
         [
             // wierd case, but valid, nonetheless
- default_(cout << val("<any...>") << endl)
+ //default_(cout << val("<any...>") << endl)
+ default_(cout << ref("<any...>") << endl)
         ]
     );
 
@@ -45,10 +55,14 @@
     for_each(v.begin(), v.end(),
         switch_(_1)
         [
- case_<1>(cout << val("<1>") << endl),
- case_<2>(cout << val("<2>") << endl),
- case_<3>(cout << val("<3>") << endl),
- case_<4>(cout << val("<4>") << endl)
+ //case_<1>(cout << val("<1>") << endl),
+ case_<1>(cout << ref("<1>") << endl),
+ //case_<2>(cout << val("<2>") << endl),
+ case_<2>(cout << ref("<2>") << endl),
+ //case_<3>(cout << val("<3>") << endl)//,
+ case_<3>(cout << ref("<3>") << endl),
+ //case_<4>(cout << val("<4>") << endl)
+ case_<4>(cout << ref("<4>") << endl)
         ]
     );
 
@@ -57,11 +71,16 @@
     for_each(v.begin(), v.end(),
         switch_(_1)
         [
- case_<1>(cout << val("<1>") << endl),
- case_<2>(cout << val("<2>") << endl),
- case_<3>(cout << val("<3>") << endl),
- case_<4>(cout << val("<4>") << endl),
- default_(cout << val("<over 4>") << endl)
+ //case_<1>(cout << val("<1>") << endl),
+ case_<1>(cout << ref("<1>") << endl),
+ //case_<2>(cout << val("<2>") << endl),
+ case_<2>(cout << ref("<2>") << endl),
+ //case_<3>(cout << val("<3>") << endl),
+ case_<3>(cout << ref("<3>") << endl),
+ //case_<4>(cout << val("<4>") << endl),
+ case_<4>(cout << ref("<4>") << endl),
+ //default_(cout << val("<over 4>") << endl)
+ default_(cout << ref("<over 4>") << endl)
         ]
     );
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk