"Rob Smallshire"
Boosters,
I have implemented a 'virtual container' class (i.e. it looks and behaves like it contains Objects, but it fact it doesn't) which implements an iterator interface of what are essentially bidirectional iterators.
The iterators I have now are not STL compliant and I only have 'mutable' versions of the iterators, with no corresponding const iterators.
Some guidance on how to make the best use of boost::iterator adapter would be appreciated to create fully STL compliant iterator/const_iterator pairs:
1) Out current iterators (i.e. the Base type which will be adapted) return smart reference objects when dereferenced, rather than true C++ references to objects. Will iterator adapter work in this situation?
Yes, but for conformance you'd better not give them a category higher than "input iterator". Forward iterators and above cannot return proxies from their dereference operators. They can still support decrement, but their iterator_category must be std::input_iterator_tag. The Boost sandbox contains support for a whole range of new iterator categories that will support proxy iterators without masking their traversal capabilities.
2) Furthermore, can I use the iterator_adapter to adapt our home-grown mutable iterator into a STL compliant const_iterator? Do I simply modify the Reference of the iterator_adapter template type to be a const version of my smart-reference class?
There aren't sufficient details here to say with absolute certainty, but in principle that should work. -- David Abrahams dave@boost-consulting.com * http://www.boost-consulting.com Boost support, enhancements, training, and commercial distribution