mardi 27 septembre 2016

Simple stream iterator in C++

Consider a Java-like streaming iterator:

template<class V>
struct Iterator
{
  V& next();
  bool hasNext();
}

template<class V>
struct Iterable
{
    Iterator<V> iterator();
}

How would you cast this into a std::iterator so that you can use it in find, for-loops, etc.

I think I need to start with an InputIterator, but I am struggling with the following things here:

  • meaningful end()?
  • when are they equal()?
  • what about Distance?

Aucun commentaire:

Enregistrer un commentaire