std::prev
From Cppreference
C++ Standard Library |
---|
Iterator library |
Defined in header <iterator>
|
||
template< class BidirectionalIterator >
BidirectionalIterator prev(BidirectionalIterator it, |
||
Return the nth predecessor of iterator it.
Equivalent to std::advance(it, -n); return it;
Contents |
[edit] Parameters
it | - | bidirectional iterator |
n | - | number of elements it should be descended |
[edit] Return value
The nth predecessor of iterator it.
[edit] Example
#include <iostream> #include <iterator> #include <vector> int main() { std::vector<int> v{ 3, 1, 4 }; auto it = v.end(); auto pv = std::prev(it, 2); std::cout << *pv << '\n'; }
Output:
1
[edit] See also
|
increment an iterator (function) |
|
|
advances an iterator by given distance (function) |