algorithms with input stream iterators

F

Fraser Ross

Algorithms cannot be used with input stream iterators? Is copying the range
to a temporary container before using the algorithm the usual thing to do?

Fraser.
 
V

Victor Bazarov

Fraser said:
Algorithms cannot be used with input stream iterators? Is copying the range
to a temporary container before using the algorithm the usual thing to do?

Input iterators are very limited beasts. Copying is one thing they
can do. You can also do for_each, find, count, count_if, mismatch,
equal, transform, merge, replace_copy, replace_copy_if, remove_copy,
remove_copy_if, unique_copy, partial_sort_copy, includes, set_union,
set_intersection, set_difference, set_symmetric_difference, accumulate,
inner_product, partial_sum, adjacent_difference, or
lexicographical_compare, using the input iterators (find a good book
that describes how these work).

So, I am not sure that copying is the _usual_ thing to do, it very much
depends on what algorithm you're looking at.

Victor
 
F

Fraser Ross

Your talking about input iterators not the less useful input stream
iterators. You can only define a range with input stream iterators if the
end one is the streams end which therefore allows limited use of one-pass
algorithms.

Fraser.
 
B

Bart Blommerde

Algorithms cannot be used with input stream iterators? Is copying the
range
to a temporary container before using the algorithm the usual thing to do?

Input stream iterators are not associated with containers at all (but with
input streams). Since algorithms only manipulate containers, my guess is
that copying to a temporary container is unavoidable.


Bart
 
P

Pete Becker

Bart said:
Input stream iterators are not associated with containers at all (but with
input streams). Since algorithms only manipulate containers, my guess is
that copying to a temporary container is unavoidable.

Algorithms implement sequences delineated by iterator pairs. Doesn't
matter where the sequence comes from.
 
P

Pete Becker

Pete said:
Algorithms implement sequences delineated by iterator pairs. Doesn't
matter where the sequence comes from.

Sorry, that should begin with "Algorithms manipulate sequences..."
 
T

tom_usenet

Your talking about input iterators not the less useful input stream
iterators. You can only define a range with input stream iterators if the
end one is the streams end which therefore allows limited use of one-pass
algorithms.

input stream iterators *are* a type of input iterator; how can they be
less powerful than what they are? All input iterators are 1-pass only.

You can wrap an input stream iterator in an iterator that compares
equal with an end iterator after a certain number of increments. You
could write that using boost::iterator_adapter:
http://www.boost.org/libs/iterator/doc/index.html

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top