Boost logo

Boost :

From: Dave Harris (brangdon_at_[hidden])
Date: 2002-05-17 13:22:21


In-Reply-To: <3CE51183.8A3C172_at_[hidden]>
On Fri, 17 May 2002 16:19:47 +0200 Daniel Frey (daniel.frey_at_[hidden])
wrote:
> template< typename Iterator >
> bool is_distance( Iterator first,
> call_traits< Iterator >::param_type last, // Add
> const?
> int distance ) // Should have a default?
> {
> while( distance >= 0 && first != last ) {
> ++first;
> --distance;
> }
>
> return distance == 0;
> }

This returns true if the distance is greater than that requested. Is that
the intention? I had expected the meaning to be the same as:

    template <typename iterator>
    bool is_distance( iterator first, iterator last, int n ) {
        return std::distance( first, last ) == n;
    }

but with complexity O(min(m,n)) rather than O(m) (where m is the length of
the sequence). Actually the above is O(1) for random access iterators, so
we just need to specialise for other iterators.

-- Dave Harris


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