Boost logo

Boost :

Subject: Re: [boost] [Iterator] Zip iterator for back_insert_iterators?
From: David Abrahams (dave_at_[hidden])
Date: 2008-09-09 14:50:20


on Tue Sep 09 2008, "Kris Rousey" <krousey-AT-gmail.com> wrote:

> I just tried to make a zip iterator out of two vector
> back_insert_iterators and got a very curious compile failure:
>
> /usr/include/boost/iterator/iterator_facade.hpp:653: error: invalid
> parameter type 'void'
> /usr/include/boost/iterator/iterator_facade.hpp:653: error: in
> declaration 'typename boost::detail::operator_brackets_result<Derived,
> Value, Reference>::type boost::iterator_facade<I, V, TC, R,
> D>::operator[](Difference) const'
> /usr/include/boost/iterator/iterator_facade.hpp:693: error: invalid
> parameter type 'void'
> /usr/include/boost/iterator/iterator_facade.hpp:693: error: in
> declaration 'Derived& boost::iterator_facade<I, V, TC, R,
> D>::operator+=(Difference)'
> /usr/include/boost/iterator/iterator_facade.hpp:699: error: invalid
> parameter type 'void'
> /usr/include/boost/iterator/iterator_facade.hpp:699: error: in
> declaration 'Derived& boost::iterator_facade<I, V, TC, R,
> D>::operator-=(Difference)'
> /usr/include/boost/iterator/iterator_facade.hpp:705: error: invalid
> parameter type 'void'
> /usr/include/boost/iterator/iterator_facade.hpp:705: error: in
> declaration 'Derived boost::iterator_facade<I, V, TC, R,
> D>::operator-(Difference) const'
>
> It seems that even though back_insert_iterator has an output_iterator
> tag, iterator_facade still trying to define random access operators.

That's not exactly true; the operator[] is only supposed to be
instantiated if used, but we never considered that someone would try to
use Difference=void.

> If assignment and incrementing are the only valid operations on an
> iterator (as is the case with output iterators), then doesn't it make
> sense to support a difference_type of void?

I guess. It couldn't hurt, though, to leave the Difference parameter as
std::ptrdiff_t. If you really want
std::iterator_traits<I>::difference_type to be void, you'd normally just

   typedef void difference_type;

inside your derived iterator body. However, you're using zip_iterator.

> Is this a curiosity of my stdlib implementation? A Boost.Iterator
> library oversight?

Probably the latter.

> A Boost.Iterator conscious design decision? Or a
> loose nut behind the keyboard trying something he shouldn't?

Heh, maybe both. We didn't test the library too well on output
iterators.

Try this patch to boost/iterator/iterator_facade.hpp; does it fix the
problem for you?



-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk