os/ossrv/ossrv_pub/boost_apis/boost/xpressive/proto/compiler/conditional.hpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 ///////////////////////////////////////////////////////////////////////////////
     2 /// \file conditional.hpp
     3 /// A special-purpose proto compiler for compiling an expression either one
     4 /// way or another depending on the properties of the expression.
     5 //
     6 //  Copyright 2004 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_COMPILER_CONDITIONAL_HPP_EAN_04_01_2005
    11 #define BOOST_PROTO_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/proto_fwd.hpp>
    16 
    17 namespace boost { namespace proto
    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
    45         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