prev
namespace opentl {
template <typename It>
requires opentl::iterator<It>
constexpr It prev(It it, opentl::ptrdiff_t n = 1) noexcept;
}
Returns a copy of the iterator backtracked by n positions.
Declared in <iterator/prev.hpp>.
Template Parameters
| Name | Description |
|---|---|
It |
The iterator type. |
Parameters
| Name | Description |
|---|---|
it |
The iterator to backtrack. |
n |
The number of positions to backtrack by, negative values advance. |
Return Value
A copy of the iterator backtracked by n positions, the original iterator is left unchanged.
Example
#include <opentl/iterator.hpp>
int main() {
int values[] = { 1, 2, 3, 4 };
int* it = values + 3;
auto second_last = opentl::prev(it); // points to 3
auto first = opentl::prev(it, 3); // points to 1
}