#include <list>
#include <string>
#include <iostream>
struct Point {
std:: string name;
} ;
int main( )
{
std:: list < Point> _pointList{ { "foo" } , { "bar" } , { "baz" } } ;
if ( _pointList.size ( ) > 1 )
{
std:: list < Point> :: iterator itr;
std:: list < Point> :: iterator itr2;
for ( itr = _pointList.begin ( ) ; itr ! = _pointList.end ( ) ; itr++ )
{
//set the second iterator to the next Point in the list.
itr2 = itr;
itr2++ ;
if ( itr2 == _pointList.end ( ) )
itr2 = _pointList.begin ( ) ;
std:: cout << "The first point's name is: " << itr- > name << '\n '
<< "The second point's name is: " << itr2- > name << '\n ' ;
}
}
}
I2luY2x1ZGUgPGxpc3Q+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDxpb3N0cmVhbT4Kc3RydWN0IFBvaW50IHsKICAgIHN0ZDo6c3RyaW5nIG5hbWU7Cn07CmludCBtYWluKCkKewogICAgc3RkOjpsaXN0PFBvaW50PiBfcG9pbnRMaXN0e3siZm9vIn0sIHsiYmFyIn0sIHsiYmF6In19OwogICAgaWYoX3BvaW50TGlzdC5zaXplKCkgPiAxKQogICAgewogICAgICAgIHN0ZDo6bGlzdDxQb2ludD46Oml0ZXJhdG9yIGl0cjsKICAgICAgICBzdGQ6Omxpc3Q8UG9pbnQ+OjppdGVyYXRvciBpdHIyOwoKICAgICAgICBmb3IoaXRyID0gX3BvaW50TGlzdC5iZWdpbigpOyBpdHIgIT0gX3BvaW50TGlzdC5lbmQoKTsgaXRyKyspCiAgICAgICAgewogICAgICAgICAgICAvL3NldCB0aGUgc2Vjb25kIGl0ZXJhdG9yIHRvIHRoZSBuZXh0IFBvaW50IGluIHRoZSBsaXN0LgogICAgICAgICAgICBpdHIyID0gaXRyOwogICAgICAgICAgICBpdHIyKys7CiAgICAgICAgICAgIGlmKGl0cjIgPT0gX3BvaW50TGlzdC5lbmQoKSkKICAgICAgICAgICAgICAgaXRyMiA9IF9wb2ludExpc3QuYmVnaW4oKTsKCiAgICAgICAgICAgIHN0ZDo6Y291dCA8PCAiVGhlIGZpcnN0IHBvaW50J3MgbmFtZSBpczogIiA8PCBpdHItPm5hbWUgPDwgJ1xuJwogICAgICAgICAgICAgICAgICAgICAgPDwgIlRoZSBzZWNvbmQgcG9pbnQncyBuYW1lIGlzOiAiIDw8IGl0cjItPm5hbWUgPDwgJ1xuJzsKICAgICAgICB9CiAgICB9Cn0K