446,193 Members | 826 Online
Need help? Post your question and get tips & solutions from a community of 446,193 IT Pros & Developers. It's quick & easy.

# algorithms with input stream iterators

 P: n/a 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. Jul 22 '05 #1
6 Replies

 P: n/a Fraser Ross wrote: 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 Jul 22 '05 #2

 P: n/a 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. Jul 22 '05 #3

 P: n/a > 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 Jul 22 '05 #4

 P: n/a Bart Blommerde wrote: 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. Algorithms implement sequences delineated by iterator pairs. Doesn't matter where the sequence comes from. -- Pete Becker Dinkumware, Ltd. (http://www.dinkumware.com) Jul 22 '05 #5

 P: n/a Pete Becker wrote: Bart Blommerde wrote: 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. Algorithms implement sequences delineated by iterator pairs. Doesn't matter where the sequence comes from. Sorry, that should begin with "Algorithms manipulate sequences..." -- Pete Becker Dinkumware, Ltd. (http://www.dinkumware.com) Jul 22 '05 #6

 P: n/a On Fri, 20 Aug 2004 15:30:15 +0100, "Fraser Ross" wrote: Your talking about input iterators not the less useful input streamiterators. You can only define a range with input stream iterators if theend one is the streams end which therefore allows limited use of one-passalgorithms. 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 Jul 22 '05 #7

### This discussion thread is closed

Replies have been disabled for this discussion.