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

标签 c++ boost boost-proto

我正在阅读 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<< [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::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*)"(")) << boost::proto::value [with Expr = boost::proto::exprns_::expr >, 0l>](((const boost::proto::exprns_::expr >, 0l>&)((const boost::proto::exprns_::expr >, 0l>*)expr)))'

最佳答案

这是哪个原型(prototype)版本?最新的不再需要 << 重载,并且默认为 typeid 以在需要时显示名称。你能发布实际的错误消息吗?

关于c++ - 如何使 boost-proto 函数表达式可流化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8213674/

相关文章:

c++ - std::map::find 性能是否取决于 key 大小?

C++ Boost 线程。如何使用递归尝试锁?死锁发生在并发代码中

c++ - boost::proto::is_aggregate 为聚合类型时返回 false

c++ - boost.proto + 就地修改表达式树

c++ - 使用 boost::proto 构建 s-expression

c++ - C++/VS2010 中 sprintf 的奇怪行为

c++ - 无法将 GLFW 库与其在 Ubuntu 18.04 上的头文件链接起来

c++ - 如何在 Qt for Embedded Linux 中定位和使用字体?

c++ - 如何获取字符串中所有发现的 boost::regex 模式的位置?

c++ - 具有适配 std::pair 点类型的 R-Tree 查询