Boost logo

Boost :

From: Victor A. Wagner, Jr. (vawjr_at_[hidden])
Date: 2002-08-09 14:56:24

At Thursday 2002/08/08 08:06, you wrote:
>There are only 3 or 4 algorithms that receive an _n argument though many
>times I've wanted to do a copy using an n or bound some other algorithm
>for n elements. In the case of strings the problem is solved since I can
>look up the function in string's many function interface, but many other
>classes and range types do not provide me this freedom. So, my question
>is: Is there such a thing as a bounded_iterator (for lack of a different name)?
>My idea of a bounded_iterator would have an interface similar to
>filter_iterator, except it gets a difference_type bound. It maintains
>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);
>Is there such a thing? (If not, is there any interest in having such a
>thing?) I tried to look on the site but didn't seem to find something
>like this, although using counting_iterator in some algorithms might give
>a similar effect. Perhaps using counting iterator with a filter and
>std::less might do something like it?

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));

this would also have the advantage that you could (at the same time) write
a bounded std::advance(iterator, endlimit, count);
which, come to think of it, is exactly bounded_iterator_end(.....)

no new class required, just a templated free function.

Victor A. Wagner Jr.
PGP RSA fingerprint = 4D20 EBF6 0101 B069 3817 8DBF C846 E47A
PGP D-H fingerprint = 98BC 65E3 1A19 43EC 3908 65B9 F755 E6F4 63BB 9D93
The five most dangerous words in the English language:
               "There oughta be a law"

Boost list run by bdawes at, gregod at, cpdaniel at, john at