简体   繁体   中英

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

When I attempt to assign a variable to that iterator, i get the error: expected a ";" , where vec is a thrust::device_vector<my_type> , j is some int , and my_type is a template type:

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

Is this the correct way to loop over the vector? Am I declaring i as the correct type?

Standard containers use iterators for traversing through a collection of other objects (ie its elements), since iterator is abstract concept implemented in all standard containers, you can implement iterators in the following way:

typename thrust::device_vector<my_type>::iterator it = vec.begin();
for (it; it != vec.end(); it = it+j) 
   Foo(*it);

Here's a reference to STL containers: http://www.cplusplus.com/reference/stl/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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