2011-11-21 70 views
1

我正在学习boost-proto教程,并用lazy pow函数示例解决了这个问题。这是示例代码:如何使boost-proto函数表达式流式传输?

// 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敌不过 '运算< <' ::运算< < [与_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_: ((const const boost :: proto :: exprns _ :: expr>,0l> *)expr)))((const boost :: proto :: exprns _ :: expr>,0l> &) '

回答

2

这是哪个原始版本?最新不需要< <重载,并且如果需要,默认为typeid以显示名称。你能发布实际的错误信息吗?

+0

嗨,对不起,我以为我会收到一封电子邮件,当有人回复,所以我没有检查。我会添加上面的错误。我认为我使用的计算机已经提升了1.40,或许,正如你所说的,这个问题会随着更新的版本而消失。感谢您的帮助。 –

+0

这确实是在更高版本中修复的东西。 –