// TestProto.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include using namespace std; namespace proto = boost::proto; struct guard_tag{}; // grammar forbidding address of for terminals struct terminal_grammar : proto::not_ > {}; // Forward-declare an expression wrapper template struct mp_terminal; struct sm_domain : proto::domain< proto::generator, terminal_grammar > {}; template struct mp_terminal : proto::extends, sm_domain> { typedef proto::extends, sm_domain> base_type; // Needs a constructor mp_terminal(Expr const &e = Expr()) : base_type(e) {} // Unhide Proto's overloaded assignment operator using base_type::operator=; }; template struct GuardOR { template bool operator()(FSM& fsm,EVT const& evt,SourceState& src,TargetState& tgt) { return (T1()(fsm,evt,src,tgt) || T2()(fsm,evt,src,tgt)); } }; template struct GuardAND { template bool operator()(FSM& fsm,EVT const& evt,SourceState& src,TargetState& tgt) { return (T1()(fsm,evt,src,tgt) && T2()(fsm,evt,src,tgt)); } }; template struct GuardNOT { template bool operator()(FSM& fsm,EVT const& evt,SourceState& src,TargetState& tgt) { return !(T1()(fsm,evt,src,tgt)); } }; struct BuildGuards : proto::or_< proto::when< proto::logical_or, GuardOR() >, proto::when< proto::logical_and, GuardAND() >, proto::when< proto::logical_not, GuardNOT() >, proto::when < proto::terminal, proto::_() > > {}; struct True : mp_terminal::type> { template bool operator()(T&) { std::cout << "always true" << std::endl; return true; } }; struct False : mp_terminal::type> { template bool operator()(T& ) { std::cout << "always false" << std::endl; return false; } }; struct Dummy1 : mp_terminal::type> { template bool operator()(T& ) { std::cout << "dummy" << std::endl; return true; } }; template void print_guard(Expr const& expr) { cout << "in print_guard" << endl; cout << "matches:" << proto::matches::value << endl; typedef boost::result_of::type result_type; cout << "result_type" << endl; cout << typeid(result_type).name() << endl; cout << "end print_guard" << endl; } int main() { print_guard((True()&& Dummy1())); print_guard((True()|| False())); print_guard( ( True()&& (Dummy1() || !(False() || True())) ) ); print_guard((True()|| !False())); print_guard( (!False()) ); return 0; }