473,382 Members | 1,147 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,382 software developers and data experts.

Equality on input iterators

Hello.

A small question with regards input iterators.

Table 72 of the standard says with regards ++r on an input iterator r:

"any copies of the previous value of r are no longer required to be
dereferencable or in the domain of =="

Consider therefore the following code segment, where r is a currently
valid dereferencable input iterator.

a=r;
++r;

if(a==a) {} // Line 1
if(a==r) {} // Line 2
++a; // Line 3
a=r; // Line 4
I assume therefore lines 1,2 and 3 are undefined and anything could
happen (including a crash).
Line 4 is defined (although to be honest fairly pointless)

Is this a correct reading?

Thank you

Azumanga
Jul 22 '05 #1
2 1238
Azumanga wrote:
A small question with regards input iterators.

Table 72 of the standard says with regards ++r on an input iterator r:

"any copies of the previous value of r are no longer required to be
dereferencable or in the domain of =="

Consider therefore the following code segment, where r is a currently
valid dereferencable input iterator.

a=r;
++r;

if(a==a) {} // Line 1
if(a==r) {} // Line 2
++a; // Line 3
a=r; // Line 4
I assume therefore lines 1,2 and 3 are undefined and anything could
happen (including a crash).
Line 4 is defined (although to be honest fairly pointless)

Is this a correct reading?


I can't really vouch for its "correctness", I can only say that I read it
the same way. You could ask for clarification from the Committee members
in comp.std.c++ or comp.lang.c++.moderated.

Victor
Jul 22 '05 #2
> Consider therefore the following code segment, where r is a currently
valid dereferencable input iterator.

a=r;
++r;

if(a==a) {} // Line 1
if(a==r) {} // Line 2
++a; // Line 3
a=r; // Line 4
I assume therefore lines 1,2 and 3 are undefined and anything could
happen (including a crash).
Line 4 is defined (although to be honest fairly pointless)

Is this a correct reading?


Yes.

Input iterators are very, very limited. If you want to be able to do #1-3
above, you need at least a forward iterator.
Jul 22 '05 #3

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

Similar topics

6
by: Fraser Ross | last post by:
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.
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 = ...
40
by: Ike Naar | last post by:
In K&R "The C++ programming language (2nd ANSI C edition), the reference manual states (paragraphs 7.9 and 7.10) that pointer comparison is undefined for pointers that do not point to the same...
2
by: Marcel Sottnik | last post by:
Hallo NG Does anyone have an idea how could one implement, a general routine for value equality ? I mean something using Reflections to get all the members of a class and compare them...
8
by: Mateusz Łoskot | last post by:
Hi, I know iterator categories as presented by many authors: Stroustrup, Josuttis and Koenig&Moo: Input <---| |<--- Forward <--- Bidirectional <--- Random Output <---|
37
by: spam.noam | last post by:
Hello, Guido has decided, in python-dev, that in Py3K the id-based order comparisons will be dropped. This means that, for example, "{} < " will raise a TypeError instead of the current...
2
by: KOFKS | last post by:
I have come across a problem when I'm reading "comp.lang.c FAQ list · Question 12.1". This item is about char c; while((c = getchar()) != EOF) ... One paragraph of the item writes:"If type...
8
by: desktop | last post by:
In accelerated C++ on page 146 there is this example: template <class In, class Out> Out copy(In begin, In end, Out dest) { While (begin != end) *dest++ = *begin++; return dest; }
33
by: cesco | last post by:
Hi, say I have a string like the following: s1 = 'hi_cat_bye_dog' and I want to replace the even '_' with ':' and the odd '_' with ',' so that I get a new string like the following: s2 =...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.