David Abrahams wrote:
So I can use std::random_access_iterator_tag instead?
Not with your iterator definition; you'd be lying to the standard library. A standard random access iterator has a reference type of value_type&. Without that, your iterator is just an input iterator from the STL point-of-view.
Does that mean that I cannot create a standard conforming random access iterator for a class that behaves as a read-only proxy for values calculated on-the-fly when requested?
I simply want an iterator that works with current STL as random iterator.
Then use a real reference type. Sorry, the STL iterator design took a limited worldview and you have to conform to it if you want to get all the expected optimizations.
So the best way is to define distance(MyIterator, MyIterator); lower_bound... etc. in namespace std?
Class Demo uses a std::size_t as index type. How do I build my iterator with iterator_facade?
Use a signed distance type; that's a requirement of STL
I kind of fixed it by overloading operator- in order to avoid -distance_to. Now it "works". Is this dangerous?
(and new-style) iterators.
So using std::size_t as index argument type is a bad idea if I want to plug iterators? I mean: AFAIK it is not guaranteed that I have a signed type that can hold std::size_t. Correct me if I am wrong, please. Markus