473,408 Members | 1,788 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

algorithms with input stream iterators

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 1690
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
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
> 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
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
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
On Fri, 20 Aug 2004 15:30:15 +0100, "Fraser Ross"
<fraserATmembers.v21.co.unitedkingdom> wrote:
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
Jul 22 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: sks_cpp | last post by:
Are the standard library functions pertinent to both sequence containers and associative containers? For example, if "find_if", "remove_if", etc... valid for both lists, deques, vectors, sets,...
1
by: rg | last post by:
Dear all, I was wondering whether there was a C++ STL compliant way of using std::map iterators with the standard STL algorithms. I know there is the select1st and select2nd adaptors but they...
24
by: Lasse Vågsæther Karlsen | last post by:
I need to merge several sources of values into one stream of values. All of the sources are sorted already and I need to retrieve the values from them all in sorted order. In other words: s1 = ...
0
by: gary_dr | last post by:
What's so special about istream_iterator that prevents me from determining the distance between two of them. In the code below, search() does return a foundAt iterator that points to the location...
4
by: fastback66 | last post by:
Evidently per the C++ standard, it is not possible to measure the distance between two stream iterators, because two non-end-of-stream iterators are equal when they are constructed from the same...
27
by: Pete | last post by:
I'm doing exercise 8-2 from "Accelerated C++" where we're supposed to implement library algorithms, trying to minimize the number of iterator operations. I have two questions so far. First,...
4
by: CoreyWhite | last post by:
/* WORKING WITH STRINGS IN C++ IS THE BEST WAY TO LEARN THE LANGUAGE AND TRANSITION FROM C. C++ HAS MANY NEW FEATURES THAT WORK TOGETHER AND WHEN YOU SEE THEM DOING THE IMPOSSIBLE AND MAKING...
12
by: subramanian100in | last post by:
Below is my understanding about count algorithms. Return type of count and count_if algorithms is iterator_traits<InputIterator>::difference_type. If the container contains more than...
3
by: subramanian100in | last post by:
I am copying the following lines as it is, from Stanley Lippman's C++ Primer 4th edition, page 418(First paragraph). It says: "Although the map and set types provide bidirectional iterators, we...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.