std::ranges::subrange<I,S,K>::prev - cppreference.com (original) (raw)

Returns a copy of *this whose _[begin](../subrange.html#begin "cpp/ranges/subrange")_ is decremented (or incremented if n is negative). The actual decrement (or increment) operation is performed by advance().

Equivalent to:auto tmp = *this;
tmp.advance(-n);
return tmp;.

[edit] Parameters

n - number of decrements of the iterator

[edit] Return value

As described above.

[edit] Notes

The difference between this function and advance() is that the latter performs the decrement (or increment) in place.

[edit] Example

#include #include #include #include   int main() { std::list list{1, 2, 3, 4, 5}; std::ranges::subrange sub{std::next(list.begin(), 2), std::prev(list.end(), 2)}; std::println("{} {} {}", sub, sub.prev(), sub.prev(2)); }

Output:

[edit] See also

| | obtains a copy of the subrange with its iterator advanced by a given distance (public member function) [edit] | | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | | advances the iterator by given distance (public member function) [edit] | | | decrement an iterator (function template) [edit] | | | decrement an iterator by a given distance or to a bound(algorithm function object)[edit] |