使用增强融合显示一个扁平的凤凰表情
Displaying a Flattened Phoenix Expression using Boost Fusion
根据Proto用户指南的表达式作为融合序列部分,我达到了迭代扁平原型表达式的地步:_1 + 2 + 3 + 4
:
#include <iostream>
#include <boost/phoenix.hpp>
namespace proto = boost::proto;
namespace fusion = boost::fusion;
namespace phoenix = boost::phoenix;
struct display
{
template<typename T>
void operator()(T const &t) const
{
std::cout << t << std::endl;
}
};
boost::proto::terminal<int>::type const _1 = {1};
int main(int argc, char *argv[])
{
fusion::for_each(
fusion::transform(
proto::flatten(_1 + 2 + 3 + 4)
, proto::functional::value()
)
, display()
);
return 0;
}
_1
占位符如上所示使用proto::terminal
定义。我还想用提高凤凰;然而,如果我在fusion::for_each
的调用中使用boost::phoenix::arg_names
中定义的_1
版本,我得到一个错误:不能将' std::ostream{又名std::basic_ostream} '左值绑定到' std::basic_ostream&& ' 。我可以像这样在融合变换中使用凤凰占位符吗?
phoenix::arg_names::_1
没有ostream插入器。不过我们可以很容易地加一个。我用clang++ (trunk)来编译:
#include <iostream>
#include <boost/phoenix.hpp>
namespace proto = boost::proto;
namespace fusion = boost::fusion;
namespace phoenix = boost::phoenix;
struct display
{
template<typename T>
void operator()(T const &t) const
{
std::cout << t << std::endl;
}
};
namespace boost { namespace phoenix
{
template<int N>
std::ostream& operator<<(std::ostream& sout, argument<N> const& arg)
{
return sout << "_" << N;
}
}}
int main()
{
fusion::for_each(
fusion::transform(
proto::flatten(phoenix::arg_names::_1 + 2 + 3 + 4)
, proto::functional::value()
)
, display()
);
}
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 运行同一解决方案的另一个项目的项目
- 挂起和取消挂起一个文件DLL
- 用C++中的一个变量定义一个常量
- 函数向量_指针有不同的原型,我可以构建一个吗
- 在c++中用vector填充一个简单的动态数组
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 预处理器:插入结构名称中的前一个行号
- 我在c++代码中生成了一个运行时#3异常
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 从链接列表c++中删除一个项目
- 告诉一个 const char 数组,除了编译时 C 样式的字符串外,它不以 '