/usr/include/boost/phoenix/statement
Edit: /usr/include/boost/phoenix/statement/if.hpp (4576B)
/*==============================================================================
Copyright (c) 2001-2010 Joel de Guzman
Copyright (c) 2010 Eric Niebler
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)
==============================================================================*/
#ifndef BOOST_PHOENIX_STATEMENT_IF_HPP
#define BOOST_PHOENIX_STATEMENT_IF_HPP
#include
#include
#include
#include
#include
#include
#include
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable: 4355) // 'this' used in base member initializer list
#endif
namespace boost { namespace phoenix
{
template struct if_actor;
}}
BOOST_PHOENIX_DEFINE_EXPRESSION_EXT(
if_actor
, (boost)(phoenix)(if_)
, (meta_grammar) // Cond
(meta_grammar) // Then
)
BOOST_PHOENIX_DEFINE_EXPRESSION(
(boost)(phoenix)(if_else_statement)
, (meta_grammar) // Cond
(meta_grammar) // Then
(meta_grammar) // Else
)
namespace boost { namespace phoenix
{
////////////////////////////////////////////////////////////////////////////
// If-Else statements
////////////////////////////////////////////////////////////////////////////
// Function for evaluating lambdas like:
// if_( foo )[ bar ]
// and
// if_( foo )[ bar ].else_[ baz ]
struct if_else_eval
{
typedef void result_type;
template
result_type
operator()(Cond const & cond, Then const & then, Context const & ctx) const
{
if(boost::phoenix::eval(cond, ctx))
boost::phoenix::eval(then, ctx);
}
template
result_type
operator()(
Cond const & cond
, Then const & then
, Else const & else_
, Context const & ctx
) const
{
if(boost::phoenix::eval(cond, ctx))
boost::phoenix::eval(then, ctx);
else
boost::phoenix::eval(else_, ctx);
}
};
template
struct default_actions::when
: call
{};
template
struct default_actions::when
: call
{};
// Generator for .else_[ expr ] branch.
template
struct else_gen
{
else_gen(Cond const & cond_, Then const & then_)
: cond(cond_)
, then(then_) {}
template
typename expression::if_else_statement::type const
operator[](Else const & else_) const
{
return expression::if_else_statement::make(cond, then, else_);
}
Cond cond;
Then then;
};
// We subclass actor so we can provide the member else_ (which is an
// else_gen responsible for the .else_[ expr ] branch).
template
struct if_actor : actor
{
typedef actor base_type;
if_actor(base_type const & base)
: base_type(base)
, else_(proto::child_c<0>(*this), proto::child_c<1>(*this))
{}
typedef typename proto::result_of::child_c::type cond_type;
typedef typename proto::result_of::child_c::type then_type;
else_gen else_;
};
template
struct is_actor >
: mpl::true_
{};
// Generator for if( cond )[ then ] branch.
template
struct if_gen
{
if_gen(Cond const & cond_)
: cond(cond_) {}
template
typename expression::if_::type const
operator[](Then const & then) const
{
return expression::if_::make(cond, then);
}
Cond cond;
};
template
inline
if_gen const
if_(Cond const & cond)
{
return if_gen(cond);
}
}}
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif