![](/img/trans.png)
[英]auto it = vector.begin() resulting type is not convertible to const_iterator
[英]How to store the vector.begin() iterator of template type in thrust?
当我尝试将变量分配给该迭代器时,出现错误: expected a ";"
,其中vec
是thrust::device_vector<my_type>
, j
是一些int
,而my_type
是模板类型:
for (thrust::device_vector<my_type>::iterator i = vec.begin(); i < vec.end(); i += j) Foo(i);
这是遍历向量的正确方法吗? i
是在声明i
是正确的类型吗?
标准容器使用迭代器遍历其他对象(即其元素)的集合,因为迭代器是在所有标准容器中实现的抽象概念,所以可以通过以下方式实现迭代器:
typename thrust::device_vector<my_type>::iterator it = vec.begin();
for (it; it != vec.end(); it = it+j)
Foo(*it);
这是对STL容器的参考: http : //www.cplusplus.com/reference/stl/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.