From: Yitzhak Sapir (yitzhaks_at_[hidden])
Date: 2002-08-11 04:46:13
> From: Victor A. Wagner, Jr. [mailto:vawjr_at_[hidden]]
> >My idea of a bounded_iterator would have an interface similar to
> >filter_iterator, except it gets a difference_type bound. It
> >count through ++, --, and += of how far you are from the
> bounds, and any
> >point beyond the bounds is considered end.
> >This way doing:
> > std::copy (make_bounded_iterator(str.begin(),
> str.end(), 5),
> > make_bounded_iterator(str.end()), std::back_inserter(copy_of_str));
> >would be equivalent to
> > strncpy (new, str, 5);
> wouldn't a bounded_iterator_end() work better? it would be used as
> std::copy(str.begin(), bounded_iterator_end(str.begin(),
> str.end(), 5), std::back_inserter(copy_of_str));
It would work better on random access iterators.
It might/would work worse on bidirectional and forward iterators, since you're requiring two passes on the range instead of one. I really can't say which one would work slower since your method requires multiple passes, but mine has a little more overhead on each increment and compare.
But worse than that, it wouldn't work at all on input and output iterators. And that's the problem.
I didn't think of the fact this method would be more straightforward for random access iterators, since my goal was more to have a solution that works for input iterators. But using template metaprogramming, you could have this be the method used for random access iterators, and also allow a special form in case the bound size is known at compile time.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk