stl list how do swap iterators?

Write your question here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
                        list <string>::iterator it = myList.begin();
	                string firstLine;
			string secondLine;
			string tempbucket;
			list <string>::iterator it2;
			
			cout << "Enter first line to swap (Line 1 is 1, Line 5 is 5): ";
			cin >> firstLine;
			cout << "Enter second line to swap (Line 1 is 1, Line 5 is 5): ";
			cin >> secondLine;
			
			advance(it,firstLine);
			advance(it2,secondLine);
			myList.swap(*it,*it2);
1
2
if( a < lst.size() && b < lst.size() ) // swap lines #a and #b in the list
    std::iter_swap( std::next( lst.begin(), a ), std::next( lst.begin(), b ) ) ;

http://coliru.stacked-crooked.com/a/e7e720a1c5f20714
im using C++ 98
1
2
3
4
5
6
template < typename ITERATOR >
ITERATOR my_next( ITERATOR iter, typename std::iterator_traits<ITERATOR>::difference_type n = 1 )
{
    std::advance( iter, n ) ;
    return iter ;
}


And then:
1
2
    if( a < lst.size() && b < lst.size() ) // swap lines #a and #b in the list
        std::iter_swap( my_next( lst.begin(), a ), my_next( lst.begin(), b ) ) ;


http://coliru.stacked-crooked.com/a/7398e3bc0a1df843
im using C++ 98

in 2017 this is simply not good enough ...
im learning the basics

im probably going to learn news things later on
no codes i just want know whats going on
im learning the basics

im probably going to learn news things later on


To be frank, that's no reason to use C++98. It's just going to make things harder for you.

A valid reason might be if one were working an an existing C++98 code base.
Topic archived. No new replies allowed.