Как определить тип, возвращаемый eval в выражении proto? - PullRequest
4 голосов
/ 23 января 2012

Я определил контекст для моей грамматики, который основан на типах ввода, что-то вроде приведенного ниже фрагмента.Я скучаю по типам, где ????are.

Прежде чем я начну писать рекурсивные шаблоны, чтобы понять их, есть ли что-нибудь в прото уже?

template<typename PlaceholderTypes>  // mpl vector of placeholder types
class calculator_context
    : public proto::callable_context< calculator_context<PlaceholderTypes>, proto::null_context const >
{
public:

    template<typename T>
    struct MakePtrType
    {  
        typedef boost::shared_ptr<T> type;
    };

    // Values to replace the placeholders
    typedef typename boost::mpl::transform<PlaceholderTypes,MakePtrType<boost::mpl::_1> >::type inputTypes;    
    typename boost::fusion::result_of::as_vector<typename inputTypes::type>::type args;

    // Handle the placeholders:
    template<int I>
    typename boost::shared_ptr<boost::mpl::at<PlaceholderTypes,boost::mpl::int_<I> > >::type operator()(proto::tag::terminal, placeholder<I>)         
    {
        typedef typename boost::mpl::at<PlaceholderTypes,boost::mpl::int_<I> >::type param_type;

        boost::shared_ptr<param_type> p = boost::fusion::at_c<I>(this->args);
        return p;        
    }

    // Define the result type of the calculator.
    // (This makes the calculator_context "callable".)        
    typedef ??????? result_type;        

    template <typename Expr1, typename Expr2>
    result_type operator()(proto::tag::plus, const Expr1& lhs, const Expr2& rhs) 
    {        
        typedef ??? lhs_result_type; // result of proto::eval(lhs, ctx);                
        .... 
    }    
};
...