【问题标题】:How to make a boost-proto function expression streamable?如何使 boost-proto 函数表达式可流式传输?
【发布时间】:2012-01-03 01:29:05
【问题描述】:

我正在阅读 boost-proto 教程,并在惰性 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) );

编译器抱怨它没有 operator

谢谢。

编译错误是:

/usr/include/boost/proto/debug.hpp:146: 错误:'std::operator&)((std::basic_ostream >*)std::operator&)((std::basic_ostream >*)std: :operator&)((std::basic_ostream >*)std::operator&)((std::ostream*)((const boost::proto::functional::display_expr*)this)->boost::proto::functional::display_expr:: sout_)), std::setw(((const boost::proto::functional::display_expr*)this)->boost::proto::functional::display_expr::depth_)))), (((const boost::proto::functional::display_expr*)this)->boost::proto::functional::display_expr::first_ ? ((const char*)"") : ((const char*)", ") )))), boost::proto::tag::proto_tag_name((boost::proto::tag::terminal(), boost::proto::tag::terminal()))))), (( const char*)"(")) , 0l>](((const boost::proto::exprns_::expr >, 0l>&)((const boost::proto::exprns_::expr >, 0l>*)expr)))'

【问题讨论】:

    标签: c++ boost boost-proto


    【解决方案1】:

    这是哪个原型版本?最新版本不再需要

    【讨论】:

    • 嗨,对不起,我以为有人回复我会收到一封电子邮件,所以我没有检查。我将在上面添加错误。我认为我使用的计算机有 boost 1.40,所以也许,正如你所说,这个问题会随着更新的版本而消失。感谢您的帮助。
    • 这确实是在以后的版本中修复的。
    猜你喜欢
    • 2011-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-24
    • 2020-08-30
    • 1970-01-01
    • 2018-03-30
    • 2022-01-13
    相关资源
    最近更新 更多