Boost logo

Boost :

From: Thomas Becker (tmbecker1_at_[hidden])
Date: 2003-09-22 14:54:18


--- Anthony Williams
<anthony.williamsNOSPAM_at_[hidden]> wrote:
> David Abrahams <dave_at_[hidden]> writes:
> > Anthony Williams
> <anthony.williamsNOSPAM_at_[hidden]> writes:
> >
> >> David Abrahams <dave_at_[hidden]>
> writes:
> >>> Anthony Williams
> <anthony.williamsNOSPAM_at_[hidden]> writes:
> >>
> >>>> I would like to submit my "pair iterators"
> library for inclusion in
> >>>> boost. The library is described in my article
> "Pairing off Iterators" from
> >>>> Overload 51, which is available at
> >>>>
> http://cplusplus.anthonyw.cjb.net/pair_iterators.pdf
> >>
> >>> I think you may be a little late. Have you seen
> >>>
>
http://www.boost-consulting.com/boost/boost/iterator/zip_iterator.hpp
> >>> ??
> >>
> >> I hadn't. But then, you only checked it in two
> weeks ago. Does it work
> >> correctly with things like this?
> >>
> >> template<typename It>
> >> void rotate_by_one(It begin,It end)
> >> {
> >> typedef std::iterator_traits<It>::value_type
> ValueType;
> >>
> >> if(begin==end)
> >> {
> >> return;
> >> }
> >> ValueType value=*begin; // take a copy and
> keep it around
> >>
> >> for(It
> prev=begin++;begin!=end;++begin,++prev)
> >> {
> >> *prev=*begin; // overwrite the value
> copied
> >> }
> >> *prev=value; // use the copy
> >> }
> >>
> >> *that* was the bit that I found hardest to get
> working --- having a value
> >> type such that *it was a real reference, writing
> to *it updated the
> >> underlying iterators, yet copying from *it
> produced an object of the same
> >> type that *didn't* update the underlying
> iterators.
> >
> > The above code would work, but *it is not a real
> reference and
> > doesn't need to be. In fact, I'm pretty sure that
> would make the
> > iterator bigger and slower than neccessary.
>
> *it MUST be a real reference to the value type for
> Forward/bidi/random access
> Iterators (see table 74 of the standard).
>

The zip iterator that's in the Boost CVS right now was
written under the assumption that the new iterator
categories are available. These new categories were
designed primarily to solve the exact (annoying) issue
with the old categories that you mention: in order to
have certain traversal properties, such as random
access, one had to have certain access properties,
such as *it being a reference. Under the new
categories, that problem has gone away. Therefore,
what you have should be very useful in a context where
only the old categories are available, but is probably
unneccessarily heavy when the new categories are
present.

Thomas Becker
Zephyr Associates, Inc.
Zephyr Cove, NV

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com


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