1

I need to create a template class based on the thrust device vector. However, I cannot overload the iterator, if the class is a template. Does someone know how I can come around this problem? It seems like the iterator type is not a template. I am yet not sure how it has been implemented in thrust.

Not working:

#include <thrust/host_vector.h>
#include <thrust/device_vector.h>

template <class Type>
class F2DArray : public thrust::device_vector<Type> {
  iterator GetRowBegin(const unsigned int &y) {
    assert(y < iHeight);
    return begin()+y*iWidth;
  }

  iterator GetRowEnd(const unsigned int &y) {
    assert(y < iHeight);
    return begin()+y*iWidth+iWidth;
  }

  const_iterator GetRowBegin(const unsigned int &y) const {
    assert(y < iHeight);
    return begin()+y*iWidth;
  }

  const_iterator GetRowEnd(const unsigned int &y) const {
    assert(y < iHeight);
    return begin()+y*iWidth+iWidth;
  }
};

Error:

error: identifier "iterator" is undefined
error: identifier "iterator" is undefined
error: identifier "const_iterator" is undefined
error: identifier "const_iterator" is undefined

Working

class F2DArray : public thrust::device_vector<float> {
  iterator GetRowBegin(const unsigned int &y) {
    assert(y < iHeight);
    return begin()+y*iWidth;
  }

  iterator GetRowEnd(const unsigned int &y) {
    assert(y < iHeight);
    return begin()+y*iWidth+iWidth;
  }

  const_iterator GetRowBegin(const unsigned int &y) const {
    assert(y < iHeight);
    return begin()+y*iWidth;
  }

  const_iterator GetRowEnd(const unsigned int &y) const {
    assert(y < iHeight);
    return begin()+y*iWidth+iWidth;
  }
};
dgrat
  • 2,214
  • 4
  • 24
  • 46

0 Answers0