Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2006-11-23 08:38:32


Sebastian Redl <sebastian.redl_at_[hidden]> writes:

> Hi,
>
> A few days ago, I made a comment about std::distance() and
> std::advance() being reimplemented for the new style iterator concepts.
> Dave said that patches are welcome.
>
> So I sat down and wrote some preliminary versions of the two functions.
> They are in the attached file.
> The file parses cleanly, but I have not tried instantiating any of the
> templates yet.
>
> I have a question, though. Does it make sense to implement
> boost::distance for single pass iterators? Is there anything useful that
> could be done with the resulting information?

Sure, you could (destructively) count the number of elements remaining
in a stream. Single-pass iterators are the traversal equivalent of
input iterators, and I'm pretty sure std::distance works on those.

> Aside from that, I'd be happy to receive any suggestions for code
> improvement, adherence to Boost standards, and so on.

<snip>

> template <class BidirectionalTraversableIterator, class Distance>
> void advance(boost::bidirectional_traversal_tag,
> BidirectionalTraversableIterator &i, Distance n)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

That's "traversal," not "traversable"

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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