STL and advance() 
Author Message
 STL and advance()

Windows NT, VC++ 6.0

I have a question about std::list and the algorithm std::advance.

If I run off the end of a STL container (in this example a list) I get
"myList.end()." Sweet.

Next, I could do this:
[...]
std::list<myClass> myList;
// myList becomes populated
std::list<myClass>::iterator myIt = myList.begin();
++myIt;     // for fun advance by one.

// then "run off" the beginning
std::advance( myIt, -5 );  // that's negative five
// could be any negative number that precedes the begin() position

My test program always returns the first element in the list. Sweet.

Can I DEPEND on this behavior every time?

For the curious: In a particular situation I have to have a std:list
act as a proxy for a database (Oracle) result set (dynaset). An
[*]external object will constantly query the "DB/proxy" about it's BOF
and EOF status by actually requesting a row BOF/EOF. Icky.

* I didn't write the stupid external object, and yes, I think it's
ridiculously dumb that it has this behavior, but I can't change it. I
think it should let *me* tell it where the BOF/EOF are. "Whaddya
gonna' do?" :-)  Thanks.

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.*-*-*.com/ - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----



Fri, 09 Dec 2005 00:43:06 GMT  
 STL and advance()
According to 24.1.4, table 75 in the C++ standard, you're relying on
undefined behavior - there's no guarantee that std::advance(i,-5) will yield
begin() if i is any amount other than 5 past begin().  (In other words,
decrementing the result from begin() is undefined).

-cd

Quote:

> Windows NT, VC++ 6.0

> I have a question about std::list and the algorithm std::advance.

> If I run off the end of a STL container (in this example a list) I get
> "myList.end()." Sweet.

> Next, I could do this:
> [...]
> std::list<myClass> myList;
> // myList becomes populated
> std::list<myClass>::iterator myIt = myList.begin();
> ++myIt;     // for fun advance by one.

> // then "run off" the beginning
> std::advance( myIt, -5 );  // that's negative five
> // could be any negative number that precedes the begin() position

> My test program always returns the first element in the list. Sweet.

> Can I DEPEND on this behavior every time?

> For the curious: In a particular situation I have to have a std:list
> act as a proxy for a database (Oracle) result set (dynaset). An
> [*]external object will constantly query the "DB/proxy" about it's BOF
> and EOF status by actually requesting a row BOF/EOF. Icky.

> * I didn't write the stupid external object, and yes, I think it's
> ridiculously dumb that it has this behavior, but I can't change it. I
> think it should let *me* tell it where the BOF/EOF are. "Whaddya
> gonna' do?" :-)  Thanks.

> -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> -----==  Over 80,000 Newsgroups - 16 Different Servers! =-----



Fri, 09 Dec 2005 01:15:03 GMT  
 STL and advance()
On Sun, 22 Jun 2003 10:15:03 -0700, "Carl Daniel [VC++ MVP]"

Quote:

>According to 24.1.4, table 75 in the C++ standard, you're relying on
>undefined behavior - there's no guarantee that std::advance(i,-5) will yield
>begin() if i is any amount other than 5 past begin().  (In other words,
>decrementing the result from begin() is undefined).

Yikes! That's what I was concerned about. Rats. Back to the drawing
board.

Thank you for the answer.

If you drop your keys into molten lava just let 'em go
'cause, man, they're gone.  --  Jack Handey  :-)

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----



Fri, 09 Dec 2005 04:36:55 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. VC6 STL advance() bug?

2. ATL conflict between VC 7 STL and SGI STL - how to resolve

3. Conflict between VC 7 STL and SGI STL - how to resolve

4. STL or not to STL

5. Which STL should I replace VC6 STL with?

6. STL header files vs non-STL header files

7. SGI-STL or STL of VC++

8. Porting code from SGI STL to MSVC STL

9. STL Newbie: STL maps

10. MFC + STL < STL

11. typedef'ing iterators in MSVC's STL (not the HP STL)

12. VC++ STL v/s SGI STL Performance ???

 

 
Powered by phpBB® Forum Software