473,796 Members | 2,741 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1721
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_co py, includes, set_union,
set_intersectio n, set_difference, set_symmetric_d ifference, accumulate,
inner_product, partial_sum, adjacent_differ ence, 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"
<fraserATmember s.v21.co.united kingdom> 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
3037
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, and maps? I know that the word "iterator" is typedef'd from something for everyone of these containers so I was curious if all these functions are valid. On the same note, should I use "find_if" or "remove_if" for the following
1
2614
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 are not part of the C++ standard. I'm assuming that people will have met this problem before, what kind of solutions do you normally use for it? I could always create custom algorithms to be used specifically with maps
24
3969
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 = s2 = s3 = for value in ???(s1, s2, s3):
0
2255
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 in question, but distance() still always returns zero. However reading a chunk of file into a vector and searching the vector produces an iterator that distance() will measure properly. Evidently , it is not possible to measure the distance ...
4
2320
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 stream. I still don't quite understand why that fact is true. But... I wish to find the first occurance of some sequence in an existing stream. For the moment this stream is a file on disk, but later may be a stream from another process. Anyway,...
27
2178
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, it took me a while to figure out how to get accumulate() to compile correctly: // begin and begin2 must both be input iterators.
4
455
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 COMPACT COHERENT CODE THAT WORKS WITH STRINGS, IT ALL BEGINS TO MAKE SINCE*/ /* The basics of C++ are Classes, that build Types. Which are used to create quick and dirty routines in the smallest possible space. The Classes & Routines uses the...
12
2318
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 'difference_type' elements satisfying the condition, then count and count_if algorithm cannot return a value greater than 'difference_type'. As an example, suppose maximum value of 'difference_type' is INT_MAX.
3
1541
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 can use only a subset of the algorithms on associative containers. The problem is that key in an associative container is const. Hence, any algorithm that writes to elements in the sequence cannot be used on an associative container. We may use...
0
10467
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10244
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10201
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7558
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6802
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5454
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4130
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2931
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.