我正在學習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> &) '
嗨,對不起,我以爲我會收到一封電子郵件,當有人回覆,所以我沒有檢查。我會添加上面的錯誤。我認爲我使用的計算機已經提升了1.40,或許,正如你所說的,這個問題會隨着更新的版本而消失。感謝您的幫助。 –
這確實是在更高版本中修復的東西。 –