std::ranges...r++,--,+=,-=(3)

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

πŸ’– NAME πŸ’–

bestie, welcome to the std::ranges...r++,--,+=,-=(3) page from the C++ Standard Libary manual. This page is all about std::ranges::stride_view::iterator::operator++,--,+=,-= β€” and yes, the name is literally std::ranges::stride_view::iterator::operator++,--,+=,-= twice in the original NAME section, so we're keeping both. It's giving β€œsay it again for the people in the back.” πŸ’…

✨ Synopsis ✨

okay so here's the whole lineup, and every single one is constexpr and since C++23:

constexpr /*iterator*/& operator++();                   (1) (since C++23)
constexpr void operator++( int );                       (2) (since C++23)
constexpr /*iterator*/ operator++( int )                (3) (since C++23)
  requires ranges::forward_range<Base>;
constexpr /*iterator*/& operator--()                    (4) (since C++23)
  requires ranges::bidirectional_range<Base>;
constexpr /*iterator*/ operator--( int )                (5) (since C++23)
  requires ranges::bidirectional_range<Base>;
constexpr /*iterator*/& operator+=( difference_type n ) (6) (since C++23)
  requires ranges::random_access_range<Base>;
constexpr /*iterator*/& operator-=( difference_type n ) (7) (since C++23)
  requires ranges::random_access_range<Base>;

Increments or decrements the iterator. That's the whole vibe. πŸ¦‹

Let current_, end_, stride_, and missing_ be the data members of the iterator. Keep those names close, they're about to do main-character stuff. 🫢

  1. Equivalent to:
missing_ = ranges::advance(current_, stride_, end_);
return *this
Before the call current_ should not be equal to end_.
  1. Equivalent to ++*this;.
  2. Equivalent to auto tmp = *this; ++*this; return tmp;.
  3. Equivalent to:
ranges::advance(current_, missing_ - stride_);
missing_ = 0;
return *this;
  1. Equivalent to auto tmp = *this; --*this; return tmp;.
  2. Equivalent to:
if (n > 0)
{
    ranges::advance(current_, stride_ * (n - 1));
    missing_ = ranges::advance(current_, stride_, end_);
}
else if (n < 0)
{
    ranges::advance(current_, stride_ * n + missing_);
    missing_ = 0;
}

return *this;

If n > 0, then before the call to this function the ranges::distance(current_, end_) must be greater than stride_ * (n - 1).

Note that if n < 0, the ranges::distance(current_, end_) is always greater than (non-positive) stride_ * (n - 1).

  1. Equivalent to return *this += -n;.

🌸 Parameters 🌸

  • n β€” position relative to current location

πŸŽ€ Return value πŸŽ€

  • 1, 4, 6, 7 β€” *this
  • 2 β€” (none)
  • 3, 5 β€” a copy of *this that was made before the change

πŸ’… Example πŸ’…

This section is incomplete Reason: no example

not me crying over an empty example section 😭 but that's literally what it says, so we're not inventing one. periodt.

πŸ”₯ See also πŸ”₯

  • operator+ performs iterator arithmetic
  • operator- (function) (C++23)

πŸ¦‹ Category πŸ¦‹

  • Todo no example

xoxo, your Unix bestie πŸ’œ β€” source: http://cppreference.com, date: 2024.06.10, page: std::ranges...r++,--,+=,-=(3) πŸŽ€

πŸ“¦ where this page comes from