[iterator] Interest in abstract iterator?

Hi, Quite a few times I needed a type-erased iterator, that is somewhat similar to boost::function and boost::any with regard to functors and other objects. I've crafted a simple abstract_iterator that is capable to adopt other iterators. Main features are: * A quite small and simple implementation. * Small objects optimization. By default, adopting iterators with size of a pointer or smaller will not result in dynamic memory allocation. * The abstract_iterator is capable to adopt other abstract_iterators of the same or more relaxed iterator category without increasing the adoption level. * Most operations on the iterator introduce a virtual function call overhead. Operations involving two iterators also require a dynamic_cast. The code is in the Vault: http://tinyurl.com/yhxbkl3 Tested on MSVC 9. Is there any interest?

Andrey Semashev wrote:
Quite a few times I needed a type-erased iterator, that is somewhat similar to boost::function and boost::any with regard to functors and other objects.
You might want to take a look at http://thbecker.net/free_software_utilities/type_erasure_for_cpp_iterators/s...

On 08.02.2010 18:40, Mathias Gaunard wrote:
Andrey Semashev wrote:
Quite a few times I needed a type-erased iterator, that is somewhat similar to boost::function and boost::any with regard to functors and other objects.
You might want to take a look at http://thbecker.net/free_software_utilities/type_erasure_for_cpp_iterators/s...
Great! I knew someone must have done this before. So, do we need such a tool in Boost?

Andrey Semashev escribió:
Hi,
Quite a few times I needed a type-erased iterator, that is somewhat similar to boost::function and boost::any with regard to functors and other objects. I've crafted a simple abstract_iterator that is capable to adopt other iterators. Main features are:
* A quite small and simple implementation. * Small objects optimization. By default, adopting iterators with size of a pointer or smaller will not result in dynamic memory allocation. * The abstract_iterator is capable to adopt other abstract_iterators of the same or more relaxed iterator category without increasing the adoption level. * Most operations on the iterator introduce a virtual function call overhead. Operations involving two iterators also require a dynamic_cast.
The code is in the Vault:
Tested on MSVC 9. Is there any interest?
I'm much interested. There's also Adobe any_iterator to draw some inspiration from: http://stlab.adobe.com/classadobe_1_1any__iterator.html Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

On 2/8/2010 3:55 PM, joaquin@tid.es wrote:
I'm much interested. There's also Adobe any_iterator to draw some inspiration from:
Can I play, too? :) http://www.mr-edd.co.uk/code/opqit http://bitbucket.org/edd/opqit/wiki/Home It's not great, but there's some interesting stuff in there: * extremely small forward declaration "footprint", great for adding iterators to classes with a pimpl-ed implementation. * opaque_iterator<X, tag> convertible to opaque_iterator<const X, tag> * opaque_iterator<X, tag> convertible to opaque_iterator<X, more_relaxed_tag> One snag I hit was supporting operator-> when wrapping/type-erasing input iterators. In particular, have you tried wrapping an std::istreambuf_iterator<char>? There's some annoying wording in the standard and I'd be interested to know if you run in to the same problem. More info here, at the end: http://bitbucket.org/edd/opqit/wiki/Using_opqit Anyway, I'd like to see something like this in boost. Cheers, Edd
participants (4)
-
Andrey Semashev
-
Edd Dawson
-
joaquin@tid.es
-
Mathias Gaunard