std::ranges...brange::prev(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

✨ NAME ✨

okay so this is the std::ranges...brange::prev(3) page from the C++ Standard Libary, and bestie, the main character is literally std::ranges::subrange::prev β€” like, the name is right there twice: std::ranges::subrange::prev - std::ranges::subrange::prev. πŸ’…


🌸 Synopsis 🌸

here’s the whole vibe check, no cap:

[[nodiscard]] constexpr subrange prev( std::iter_difference_t<I> n =
1 ) const

this one is (since C++20) and it has a requirement: requires std::bidirectional_iterator<I>; β€” so bidirectional iterators only, bestie. 🫢

It gives you a subrange whose iterator is decremented by n times, or incremented by min(-n, size()) times relative to that of *this, when n >= 0 or n < 0 respectively. Literally equivalent to auto tmp = *this; tmp.advance(-n); return tmp;. And the serious warning: the behavior is undefined if the iterator is decremented after being a non-decrementable value. That’s a hard no 😭.


πŸŽ€ Parameters πŸŽ€

  • n β€” number of minimal decrements of the iterator.

πŸ’– Return value πŸ’–

A subrange whose iterator is decremented by n times or incremented by min(-n, size()) times relative to that of *this, when n >= 0 or n < 0 respectively. Same energy as above, just the return-value section saying it again. ✨


πŸ¦‹ Complexity πŸ¦‹

Generally n decrements or min(-n, size()) increments on the iterator, when n >= 0 or n < 0 respectively.

Constant if I models random_access_iterator, and either n >= 0 or std::sized_sentinel_for<S, I> is modeled. slay for random access 😌.


🌈 Example 🌈

This section is incomplete.

Reason: no example.

so no example here β€” the docs are literally telling on themselves 😭.


πŸ‘‘ See also πŸ‘‘

  • next (C++20) β€” obtains a copy of the subrange with its iterator advanced by a given distance (public member function)
  • advance (C++20) β€” advances the iterator by given distance (public member function)
  • prev (C++11) β€” decrement an iterator (function template)
  • ranges::prev (C++20) β€” decrement an iterator by a given distance or to a bound (niebloid)

πŸ“ Category πŸ“

  • Todo no example

before you close the tab: this page is from http://cppreference.com, dated 2024.06.10, and the footer title is std::ranges...brange::prev(3). mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from