F
flopbucket
Hi,
Quick question regarding pointer math. I have a simple container class
- something like std::vector<> - that I am implementing.
My iterators are implemented as pointers:
template<class T> class myContainer
{
typedef T * iterator;
typedef const T* const_iterator;
......
};
My question is, for implementing something like distance(), I have
somthing like:
unsigned long distance(myContainer<T>::iterator& a,
myContainer<T>::iterator& b)
{
return static_cast<unsigned long>(b-a);
}
This works, and I think it must always work, but I wanted to check here
with some of the experts.
Also, do you see a better way of doing this?
Thanks
Quick question regarding pointer math. I have a simple container class
- something like std::vector<> - that I am implementing.
My iterators are implemented as pointers:
template<class T> class myContainer
{
typedef T * iterator;
typedef const T* const_iterator;
......
};
My question is, for implementing something like distance(), I have
somthing like:
unsigned long distance(myContainer<T>::iterator& a,
myContainer<T>::iterator& b)
{
return static_cast<unsigned long>(b-a);
}
This works, and I think it must always work, but I wanted to check here
with some of the experts.
Also, do you see a better way of doing this?
Thanks