我正在尝试使用以下方法迭代 boost::fusion 向量:
typedef typename fusion::result_of::begin<T>::type t_iter;
std::cout << distance(begin(t), end(t)) << std::endl;
for(t_iter it = begin(t); it != end(t); next(it)){
std::cout<<deref(it)<<std::endl;
}
distance cout 语句给了我一个有限的长度 (2),但是循环似乎无限期地运行。
任何建议非常感谢!
你不能只是迭代一个Fusion像这样的向量,每个迭代器的类型可能与前一个不同(通常是)。我想这就是为什么你没有it = next(it)
在你的代码中,它会给出编译错误。
你可以使用boost::fusion::for_each
为此,与将每个元素打印到标准输出的函数对象一起:
struct print
{
template< typename T >
void operator()( T& v ) const
{
std::cout << v;
}
};
...
boost::fusion::for_each( t, print() );
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)