1 /////////////////////////////////////////////////////////////////////////////// 2 /// \file branch.hpp 3 /// A special-purpose proto1 compiler for compiling one branch of the expression 4 /// tree separately from the rest. Given an expression and a proto1 lambda, it 5 /// compiles the expression using an initial state determined by the lambda. 6 /// It then passes the result along with the current state and the visitor 7 /// to the lambda for further processing. 8 // 9 // Copyright 2007 Eric Niebler. Distributed under the Boost 10 // Software License, Version 1.0. (See accompanying file 11 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 12 13 #ifndef BOOST_PROTO_V1_COMPILER_BRANCH_HPP_EAN_04_01_2005 14 #define BOOST_PROTO_V1_COMPILER_BRANCH_HPP_EAN_04_01_2005 15 16 #include <boost/xpressive/proto/v1_/proto_fwd.hpp> 17 18 namespace boost { namespace proto1 19 { 20 21 /////////////////////////////////////////////////////////////////////////////// 22 // branch_compiler 23 template<typename Lambda, typename DomainTag> 24 struct branch_compiler 25 { 26 template<typename Op, typename State, typename Visitor> 27 struct apply 28 { 29 typedef proto1::compiler<typename tag_type<Op>::type, DomainTag> compiler_type; 30 31 // Compile the branch 32 typedef typename compiler_type::BOOST_NESTED_TEMPLATE apply 33 < 34 Op 35 , typename Lambda::state_type 36 , Visitor 37 >::type branch_type; 38 39 // Pass the branch, state and visitor to the lambda 40 typedef typename Lambda::BOOST_NESTED_TEMPLATE apply 41 < 42 branch_type 43 , State 44 , Visitor 45 >::type type; 46 }; 47 48 template<typename Op, typename State, typename Visitor> 49 static typename apply<Op, State, Visitor>::type callboost::proto1::branch_compiler50 call(Op const &op, State const &state, Visitor &visitor) 51 { 52 return Lambda::call 53 ( 54 proto1::compile(op, typename Lambda::state_type(), visitor, DomainTag()) 55 , state 56 , visitor 57 ); 58 } 59 }; 60 61 }} 62 63 #endif 64