Article View: be.comp.programming
Article #3857C++ iterators
From: Gunter Schelfhout
Date: Fri, 17 Oct 2003 20:24
Date: Fri, 17 Oct 2003 20:24
22 lines
1658 bytes
1658 bytes
In het boek van Jossutis, The C++ Standard Library kom ik het volgend
voorbeeld tegen (ingekort):
...
vector<int> coll;
// wat in de vector steken
vector<int>::iterator pos;
...
for (pos = coll.begin(); pos < coll.end(); pos += 2) {
//print
}
Over de bovenstaande for-loop zegt hij:
"The expression += 2 might result in undefined behavior if it moves the
iterator beyond the end() of the collection."
Nu, ik zit dat hier te bekijken, maar ik zie het niet. Van zodra de iterator
voorbij het end() gaat, dan wordt dit toch opgevangen door het statement
'pos < coll.end()', of niet?
Of zou het typo zijn en bedoelt hij 'pos != coll.end()'?
--
Blood, sweat & tears
Technical Details
Message-ID:
<0eYjb.84164$jN3.4351093@phobos.telenet-ops.be>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!proxad.net!proxad.net!skynet.be!skynet.be!ossa.telenet-ops.be!phobos.telenet-ops.be.POSTED!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: DUTCH,ASCII-7-bit X-Google-Thread: fcea4,bfe50767efe7e7cd,start X-Google-Attributes: gidfcea4,public X-Google-ArrivalTime: 2003-10-17 13:24:29 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!proxad.net!proxad.net!skynet.be!skynet.be!ossa.telenet-ops.be!phobos.telenet-ops.be.POSTED!not-for-mail From: Gunter Schelfhout <nospam@please.com> Subject: C++ iterators Newsgroups: be.comp.programming Lines: 22 User-Agent: KNode/0.7.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit Message-ID: <0eYjb.84164$jN3.4351093@phobos.telenet-ops.be> Date: Fri, 17 Oct 2003 20:24:28 GMT NNTP-Posting-Host: 213.118.155.28 X-Complaints-To: abuse@telenet.be X-Trace: phobos.telenet-ops.be 1066422268 213.118.155.28 (Fri, 17 Oct 2003 22:24:28 MEST) NNTP-Posting-Date: Fri, 17 Oct 2003 22:24:28 MEST Organization: Telenet Internet