find with reverse_iterators
find with reverse_iterators
- Subject: find with reverse_iterators
- From: Steve Mills <email@hidden>
- Date: Mon, 13 Nov 2006 15:57:39 -0600
Have I totally forgotten some simple STL knowledge, or is something
wrong here? std::find seems to be giving back the wrong
reverse_iterator when given std::find(list.rbegin(), list.rend(),
obj). It should be returning item 1 but is returning item 2. I've
verified that I am correct by writing my own search loop:
vector<CTextLine*>::reverse_iterator startItR, startItR2;
CTextLine* line = FindTextLine(startChar);
for(LONG i = numLines - 1; i >= 0; i--)
if(m_LineList[i] == line) {
startItR = vector<CTextLine*>::reverse_iterator(m_LineList.begin()
+ i);
break;
}
startItR2 = std::find(m_LineList.rbegin(), m_LineList.rend(), line);
check(*startItR == *startItR2);
The check assertion WILL fire. It is OK to send reverse_iterators to
find, right? As far as I can remember, it is because they know how to
act like forward iterators. Stepping into the calls I checked all of
the files (stl_algo, stl_vector, etc) and they have a modification
date of 9/11/2006 (I smell a conspiracy!;). (Actually, all the files
in /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ have
the same date.) Were those files changed in the Xcode 2.4.1 update
from 2.4?
Steve Mills
Drummer, Mac geek
http://sjmills5.home.mchsi.com/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden