首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使boost-proto函数表达式流畅?

如何使boost-proto函数表达式流畅?
EN

Stack Overflow用户
提问于 2011-11-21 22:47:53
回答 1查看 540关注 0票数 1

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

代码语言:javascript
复制
// 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)
    );    
}

现在,如果我尝试

代码语言:javascript
复制
proto::display_expr( mypow<2>(_1) );

编译器抱怨说它没有用于函数表达式的operator<<。我该如何定义一个?

谢谢。

编译器错误是:

/usr/include/boost/proto/debug.hpp:146: error: no match for‘operator<<’in‘std::operator<< ))))), boost::proto::tag::proto_tag_name((boost::proto::tag::terminal(), boost::proto::tag::terminal()))))), ((const char*)"() << boost::proto::value with Expr = boost::proto::exprns_::expr >, 0l>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-11-25 14:50:44

这是哪个原型版本?最新版本不再需要<<重载,如果需要,默认使用typeid来显示名称。你能发布实际的错误信息吗?

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8213674

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档