Implementing an iterator is more complicated than I thought. As we discussed, I
tried implementing a ForwardIterator, but this has to have a reference (T& or
const T&) as the return value of operator*(). So I looked at InputIterator
instead. This seems to be the way to go when returning proxies (see last
paragraph in the notes of the documentation:
http://en.cppreference.com/w/cpp/concept/InputIterator).
Still, to fully implement an InputIterator, we also have to implement
operator->(). This is possible, but we would need another intermediate class (a
"proxy proxy"), if I understand this correctly:
http://stackoverflow.com/questions/26495962
The stackoverflow question also says that the standard algorithms tend not to
use ->, so we might get away with not implementing it for now.
Finally, we have to specify all template parameters of iterator (because we want
both "value_type" and "reference" to be our proxy). In this case, deriving from
iterator is not that useful anymore. The struct iterator<> only consists of 5
typedefs and we cannot use these typedefs within the derived class (because
c++). So I think in this case it makes more sense to add the templates manually.
I made two commits to show what I mean.
The current state is on bitbucket:
https://bitbucket.org/FlorianPommerening/downward-issues/pull-requests/31/issue704/diff
|