1 ///////////////////////////////////////////////////////////////////////////////
2 /// \file conditional.hpp
3 /// A special-purpose proto1 compiler for compiling an expression either one
4 /// way or another depending on the properties of the expression.
5 //
6 //  Copyright 2007 Eric Niebler. Distributed under the Boost
7 //  Software License, Version 1.0. (See accompanying file
8 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 
10 #ifndef BOOST_PROTO_V1_COMPILER_CONDITIONAL_HPP_EAN_04_01_2005
11 #define BOOST_PROTO_V1_COMPILER_CONDITIONAL_HPP_EAN_04_01_2005
12 
13 #include <boost/mpl/if.hpp>
14 #include <boost/mpl/bool.hpp>
15 #include <boost/xpressive/proto/v1_/proto_fwd.hpp>
16 
17 namespace boost { namespace proto1
18 {
19 
20     ///////////////////////////////////////////////////////////////////////////////
21     // conditional_compiler
22     template<typename Predicate, typename IfCompiler, typename ElseCompiler>
23     struct conditional_compiler
24     {
25         template<typename Op, typename State, typename Visitor>
26         struct apply
27         {
28             typedef typename boost::mpl::if_
29             <
30                 typename Predicate::BOOST_NESTED_TEMPLATE apply<Op, State, Visitor>::type
31               , IfCompiler
32               , ElseCompiler
33             >::type compiler_type;
34 
35             typedef typename compiler_type::BOOST_NESTED_TEMPLATE apply
36             <
37                 Op
38               , State
39               , Visitor
40             >::type type;
41         };
42 
43         template<typename Op, typename State, typename Visitor>
44         static typename apply<Op, State, Visitor>::type
callboost::proto1::conditional_compiler45         call(Op const &op, State const &state, Visitor &visitor)
46         {
47             typedef typename apply<Op, State, Visitor>::compiler_type compiler_type;
48             return compiler_type::call(op, state, visitor);
49         }
50     };
51 
52 }}
53 
54 #endif
55