如何使boost-proto函数表达式可流化
How to make a boost-proto function expression streamable?
我正在浏览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<<'中没有匹配' 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:: south _)), std::setw(((const boost::proto::functional::display_expr*)this)->boost::proto::functional::display_expr::depth_))))), (((const boost::proto::functional::display_expr*)this)->boost::proto:: display_expr::first_ ?)((const char *)") : (( const char *)", "))))), boost::原型::标签::proto_tag_name ((boost::原型::标签::终端(),boost::原型::标签::终端 ()))))), (( const char *)"()& lt; & lt;boost::原型:价值[Expr =提高::原型::exprns_:: Expr>, 0 l>] (((const提高::原型::exprns_:: Expr>, 0 l>,) ((const提高::原型::exprns_:: Expr>, 0 l> *) Expr)))的
这是哪个原型版本?最新的不需要<<重载,如果需要,默认使用typeid来显示名称。
- C++模板函数中的初始化 - 新的初始值设定项表达式列表被视为复合表达式
- 来自 DLL 的函数调用 [表观调用的括号前面的表达式必须具有(指向-)函数类型]
- 在函数中使用 const int size 参数创建数组会在 Visual Studio 中抛出错误 C++:表达式的计
- 表达式 SFINAE:如何根据类型是否包含具有一个或多个参数的函数来选择模板版本
- 函数返回的 rvalue 引用(表达式)是 xvalue - 但没有标识?
- 折叠表达式和函数名称查找
- C++:带有大括号初始化列表的函数调用表达式 - 标准是否规定在单个元素列表的微不足道的情况下忽略大括号?
- 不是 lambda 函数中的常量表达式
- 保证逻辑 AND 表达式中的函数调用
- 函数调用在常量表达式中必须具有常量值
- Tbb 库:错误:编写自定义类函数而不是 lambda 表达式时,对函数的调用不匹配
- 错误:表达式不能用作函数
- 使用表达式 SFINAE 的函数模板的类外定义
- std::cout 在打印变量与函数表达式时的行为不同
- 构造函数中缺少表达式
- 如何在使用模板的函数调用的大括号表达式中推导多维数组的大小
- C++98 中的常量表达式函数
- gcc 是否将非常量表达式函数的内置视为常量表达式
- 试图理解基本的正则表达式函数在c++
- 错误:','令牌之前的预期主表达式 //函数调用