问题描述
我想遍历使用一个boost ::融合表达载体:
I'm trying to iterate over a boost::fusion vector using:
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;
}
距离COUT声明给了我一个有限长度(2),但环似乎会无限期地运行。
The distance cout statement gives me a finite length (2), however the loop seems to run indefinitely.
任何意见多少AP preciated!
Any advice much appreciated!
推荐答案
您不能只是一个迭代的融合的载体这样,每个迭代器的类型可能会比previous不同一个(通常是这样)。我想这就是为什么你没有 IT =下一个(它)
在code,它会给编译错误。
You can't just iterate a Fusion vector like that, the type for each iterator may be different than the previous one (and usually is). I guess that's why you don't have it = next(it)
in your code, it would give a compilation error.
您可以使用的boost ::融合:: for_each的
此,与打印每一个元素到标准输出函数对象在一起:
You could use boost::fusion::for_each
for this, together with a function object that prints each element to the standard output:
struct print
{
template< typename T >
void operator()( T& v ) const
{
std::cout << v;
}
};
...
boost::fusion::for_each( t, print() );
这篇关于迭代加速融合::矢量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!