function template
<iterator>
std::prevtemplate <class BidirectionalIterator> BidirectionalIterator prev (BidirectionalIterator it, typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
Get iterator to previous element
Returns an iterator pointing to the element that it would be pointing to if advanced-n
positions.
If it is a random-access iterator, the function uses just once operator+
or operator-
. Otherwise, the function uses repeatedly the increase or decrease operator (operator++
or operator--
) on the copied iterator until n elements have been advanced.
1
by default).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// prev example
#include <iostream> // std::cout
#include <iterator> // std::next
#include <list> // std::list
#include <algorithm> // std::for_each
int main () {
std::list<int> mylist;
for (int i=0; i<10; i++) mylist.push_back (i*10);
std::cout << "The last element is " << *std::prev(mylist.end()) << '\n';
return 0;
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4