繁体   English   中英

如何在推力中存储模板类型的vector.begin()迭代器?

[英]How to store the vector.begin() iterator of template type in thrust?

当我尝试将变量分配给该迭代器时,出现错误: expected a ";" ,其中vecthrust::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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM