如何使boost-proto函数表达式可流化

How to make a boost-proto function expression streamable?

本文关键字:表达式 函数 何使 boost-proto      更新时间:2023-10-16

我正在浏览boost-proto教程,并且在lazy pow函数示例中遇到了这个问题。下面是示例代码:

// Define a pow_fun function object
template<int Exp> // , typename Func>
struct pow_fun
{
    typedef double result_type;
    double operator()(double d) const
    {
        return pow(d, Exp);
    }
};
// Define a lazy pow() function for the calculator DSEL.
// Can be used as: pow< 2 >(_1)
template<int Exp, typename Arg>
typename proto::result_of::make_expr<
    proto::tag::function  // Tag type
  , pow_fun<Exp>          // First child (by value)
  , Arg const &           // Second child (by reference)
>::type const
mypow(Arg const &arg)
{
    return proto::make_expr<proto::tag::function>(
        pow_fun<Exp>()    // First child (by value)
      , boost::ref(arg)   // Second child (by reference)
    );    
}

现在,如果我尝试

proto::display_expr( mypow<2>(_1) );

编译器报错没有<<为函数表达式。我如何定义一个?

谢谢。

编译错误是:

/usr/include/boost/proto/debug.hpp:146:错误:在' std::operator<<'中没有匹配' operator<<'[with _Traits = std::char_traits]((std::basic_ostream>&)((std::basic_ostream>*)std::operator<<[with _Traits = std::char_traits]((std::basic_ostream>&)((std::basic_ostream>*)std::operator<<[with _Traits = std::char_traits]((std::basic_ostream>&)((std::basic_ostream>*)std::operator<<[with _CharT = char, _Traits = std::char_traits]((std::basic_ostream>&)((std::ostream*)((const boost::proto::functional::display_expr*)this)->boost::proto::functional::display_expr:: south _)), std::setw(((const boost::proto::functional::display_expr*)this)->boost::proto::functional::display_expr::depth_))))), (((const boost::proto::functional::display_expr*)this)->boost::proto:: display_expr::first_ ?)((const char *)") : (( const char *)", "))))), boost::原型::标签::proto_tag_name ((boost::原型::标签::终端(),boost::原型::标签::终端 ()))))), (( const char *)"()& lt; & lt;boost::原型:价值[Expr =提高::原型::exprns_:: Expr>, 0 l>] (((const提高::原型::exprns_:: Expr>, 0 l>,) ((const提高::原型::exprns_:: Expr>, 0 l> *) Expr)))的

这是哪个原型版本?最新的不需要<<重载,如果需要,默认使用typeid来显示名称。