473,396 Members | 2,010 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,396 software developers and data experts.

Does this look correct?

I want to go through a std::list backwards....

std::list<mytype>::reverse_iterator it;

for (it=out.rbegin(); it != out.rend(); --it)
{
...
}

Mar 9 '06 #1
11 2189
JustSomeGuy wrote:
I want to go through a std::list backwards....

std::list<mytype>::reverse_iterator it;

for (it=out.rbegin(); it != out.rend(); --it)
{
...
}


Looks correct. The only thing is that if you modify the list in the
middle of iterating through it, the iterator _may_ become invalid. If
your '...' contain something like

out.erase(it);

then it's a mistake because 'it' is invalid after that. Also, there
seems to be no need to declare 'it' outside of the 'for'. Keep it tight:

for (std::list<mytype>::reverse_iterator it = out.rbegin(); ...

V
--
Please remove capital As from my address when replying by mail
Mar 9 '06 #2
So the --it is correct... It isn't ++it (In the for loop control)

Mar 9 '06 #3
JustSomeGuy wrote:
So the --it is correct... It isn't ++it (In the for loop control)


Many iterators can implement as pointers, so...

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Mar 9 '06 #4
JustSomeGuy wrote:
So the --it is correct... It isn't ++it (In the for loop control)


Oh... Hold on... You may be onto something... Gonna check...
Mar 9 '06 #5
JustSomeGuy wrote:
So the --it is correct... It isn't ++it (In the for loop control)


You're right! It should be ++.

V
--
Please remove capital As from my address when replying by mail
Mar 9 '06 #6
Phlip wrote:
JustSomeGuy wrote:
So the --it is correct... It isn't ++it (In the for loop control)


Many iterators can implement as pointers, so...


So what? Reverse iterators are never pointers, period.

Ben
Mar 10 '06 #7
benben wrote:
Many iterators can implement as pointers, so...
So what? Reverse iterators are never pointers, period.


So thanks for completing my post; that's what.

One might thereby presume that bidirection iterators can, hence the _point_
of reverse iterators is they don't really, hence don't use rbegin() and
rend() on bidirectional iterators, etc.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Mar 10 '06 #8
"Phlip" <ph******@yahoo.com> wrote in message
news:X5******************@newssvr24.news.prodigy.n et...
One might thereby presume that bidirection iterators can, hence the
_point_ of reverse iterators is they don't really, hence don't use
rbegin() and rend() on bidirectional iterators, etc.


How's that again? You use rbegin and rend on containers, not iterators.
And if you apply rbegin to a list, what you get back is a bidirectional
iterator that traverses the list backward.
Mar 10 '06 #9
Andrew Koenig wrote:
How's that again?


I was about to tell the OP that because some iterators may implement as
pointers, they should use -- to go backwards. Then I realized I didn't
actually know that. (Yes, there have been times I went and grabbed the
manual to answer a post. I declined this time because the thread was fresh
and I trust many^W a few people here to cover such things.)

Now I realize that the point of rbegin() and rend() is to supply iterators
that algorithms think are going forward when they are really going
backwards. Cute!

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Mar 10 '06 #10
Ok.. so now that I've started a fight....
The iterator to be used is ++ and not --????
Funny how a simple question about how to iterate through a list
backwards can be so hard to ask.

Mar 13 '06 #11
JustSomeGuy wrote:
Ok.. so now that I've started a fight....
The iterator to be used is ++ and not --????
Funny how a simple question about how to iterate through a list
backwards can be so hard to ask.


You started what fight? The reverse iterator goes from the back of
the list to its beginning using ++. You can use a regular iterator
to do essentially the same, but then you'd need to use --.

V
--
Please remove capital As from my address when replying by mail
Mar 13 '06 #12

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

Similar topics

14
by: billy.becker | last post by:
I need to save a wav file that is HTTP POSTed to a php page. What does PHP5 do automatically to a POSTed variable when it puts it in the $_POST superglobal array? I haven't been able to find any...
11
by: BoonHead, The Lost Philosopher | last post by:
I think the .NET framework is great! It's nice, clean and logical; in contradiction to the old Microsoft. It only saddens me that the new Microsoft still doesn't under stand there own...
8
by: Jaime Rios | last post by:
Hi, I created a COM AddIn for Word that performs the functions that it needs to, but I needed to add the ability for the toolbar created by the COM AddIn to remember it's last position and...
5
by: David Webb | last post by:
The problem started when the Working Folder for a project was somehow set to the folder of another project. I set the correct working folder in VSS and deleted the .vbproj files that had been...
4
by: craig | last post by:
I need two methods that would allow me to extract the high and low words from in Int32. Does this look correct? Thanks!! private Int16 HighWord(Int32 Value) { Int16 newValue; newValue...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
14
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it...
7
by: Xah Lee | last post by:
Look at this page http://xahlee.org/emacs/wrap-url.html Look at it in Firebox, look at it in Safari, in Opera, and look at it in Microsoft Internet Explorer. The only fucked up case, is...
1
by: Daz | last post by:
Hi everyone. I know this question sounds stupid, but it's been plaguing me, and as I can't seem to find the answer, and can't afford to wait until the end of March for DST to kick into effect, I...
19
by: Angus | last post by:
I have a socket class CTestClientSocket which I am using to simulate load testing. I create multiple instances of the client like this: for (int i = 0; i < 5; i++) { CTestClientSocket* pTemp...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.