C++ 如何确定原始表达式上的eval返回的类型?
我为语法定义了一个上下文,它以输入类型为模板,类似于下面的代码段。我缺少的类型在哪里????是的 在我开始编写递归模板来找出它们之前,proto中是否已经有了任何东西C++ 如何确定原始表达式上的eval返回的类型?,c++,templates,boost,metaprogramming,boost-proto,C++,Templates,Boost,Metaprogramming,Boost Proto,我为语法定义了一个上下文,它以输入类型为模板,类似于下面的代码段。我缺少的类型在哪里????是的 在我开始编写递归模板来找出它们之前,proto中是否已经有了任何东西 template<typename PlaceholderTypes> // mpl vector of placeholder types class calculator_context : public proto::callable_context< calculator_context<
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);
....
}
};
模板//占位符类型的mpl向量
类计算器上下文
:public proto::callable_context
{
公众:
模板
结构MakePtrType
{
typedef boost::共享_ptr类型;
};
//替换占位符的值
typedef typename boost::mpl::transform::type inputTypes;
typename boost::fusion::result_of::as_vector::type args;
//处理占位符:
模板
typename boost::shared_ptr::type operator()(proto::tag::terminal,占位符)
{
typedef typename boost::mpl::at::type param_type;
boost::shared_ptr p=boost::fusion::at_c(this->args);
返回p;
}
//定义计算器的结果类型。
//(这使计算器上下文“可调用”。)
类型定义结果类型;
模板
结果类型运算符()(proto::tag::plus、const Expr1和lhs、const Expr2和rhs)
{
typedef???lhs_result_type;//proto::eval(lhs,ctx)的结果;
....
}
};
根据,proto::eval()的返回类型是proto::result\u of::eval::type
,因此lhs\u result\u type
typedef应该类似于typedef typename proto::result\u of::eval::type lhs\u result\u type代码>。至于你的整体结果类型
,我不确定——这不是由你作为上下文作者决定的吗?我假设它应该是您输入类型的普通类型
。。。