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

时间:2013-05-05 01:10:22

标签: c++ cuda iterator gpgpu thrust

当我尝试将变量分配给该迭代器时,我收到错误:expected a ";",其中vecthrust::device_vector<my_type>jint },my_type是模板类型:

for (thrust::device_vector<my_type>::iterator i = vec.begin(); i < vec.end(); i += j) Foo(i);

这是循环向量的正确方法吗?我是否将i声明为正确类型?

1 个答案:

答案 0 :(得分:1)

标准容器使用迭代器遍历其他对象(即其元素)的集合,因为迭代器是在所有标准容器中实现的抽象概念,您可以通过以下方式实现迭代器:

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/